Skip to content

Conversation

@radoering
Copy link
Member

@radoering radoering commented Aug 19, 2025

We did not allow importlib-metadata 8.7 because

.metadata() (and Distribution.metadata) can now return None if the metadata directory exists but not metadata file is present

I added a test and it turns out that no changes are required because such distributions are not returned when calling metadata.distributions(). Further, our code that does not expect None, does not expect empty PackageMetadata either. (It will raise an exception in both cases.)

I tested it with Python 3.10. However, importlib-metadata is only used for Python 3.9 - and it fails if the metadata is None instead of empty metadata. Further, there is already a test so that we do not need a new one: test_load_successful_with_invalid_distribution

For whomever is wondering why we should care about Python 3.9 even though its EOL is near: Newer importlib-metadata versions will be included in newer Python versions. Thus, we will probably have the same issue with Python 3.14 3.15.

Summary by Sourcery

Loosen importlib-metadata version constraint and add validation for distributions without metadata

Build:

  • Allow importlib-metadata 8.7 for Python <3.10 by removing the upper bound on the dependency

Tests:

  • Add test to ensure distributions missing metadata files are ignored by the repository loader

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Relaxed the importlib-metadata version constraint to allow 8.7 and confirmed via new tests and fixtures that distributions without METADATA files are properly ignored by the existing code.

Class diagram for distribution and metadata handling in tests

classDiagram
    class Distribution {
        +name: str
        +version: str
        +metadata: PackageMetadata | None
    }
    class PackageMetadata {
        +METADATA_FILE: str
    }
    Distribution --> PackageMetadata : metadata
    class NoMetadataDistribution {
        +name: str
        +version: str
        +metadata: None
    }
    NoMetadataDistribution --|> Distribution
Loading

File-Level Changes

Change Details Files
Relax importlib-metadata version constraint to include 8.7
  • Removed the '<8.7' upper bound from the importlib-metadata dependency
  • Updated poetry.lock to pick up the new version constraint
pyproject.toml
poetry.lock
Add tests for distributions missing METADATA files
  • Included the no_metadata distribution in the installed_results fixture list
  • Added test_load_no_metadata_file to verify that no-metadata packages return None
  • Added a NO_METADATA file to simulate a dist-info directory without metadata
tests/repositories/test_installed_repository.py
tests/repositories/fixtures/installed/lib/python3.7/site-packages/no_metadata-1.2.3.dist-info/NO_METADATA

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering force-pushed the update-importlib-metadata branch from 7ef8236 to fdf8516 Compare August 20, 2025 08:21
@radoering radoering force-pushed the update-importlib-metadata branch from fdf8516 to 3e824ca Compare August 21, 2025 16:03
@radoering radoering merged commit 576016f into python-poetry:main Aug 27, 2025
53 checks passed
mwalbeck pushed a commit to mwalbeck/docker-python-poetry that referenced this pull request Sep 26, 2025
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [poetry](https://github.com/python-poetry/poetry) ([changelog](https://python-poetry.org/history/)) | minor | `2.1.4` -> `2.2.1` |

---

### Release Notes

<details>
<summary>python-poetry/poetry (poetry)</summary>

### [`v2.2.1`](https://github.com/python-poetry/poetry/blob/HEAD/CHANGELOG.md#221---2025-09-21)

[Compare Source](python-poetry/poetry@2.2.0...2.2.1)

##### Fixed

- Fix an issue where `poetry self show` failed with a message about an invalid output format ([#&#8203;10560](python-poetry/poetry#10560)).

##### Docs

- Remove outdated statements about dependency groups ([#&#8203;10561](python-poetry/poetry#10561)).

##### poetry-core ([`2.2.1`](https://github.com/python-poetry/poetry-core/releases/tag/2.2.1))

- Fix an issue where it was not possible to declare a PEP 735 dependency group as optional ([#&#8203;888](python-poetry/poetry-core#888)).

### [`v2.2.0`](https://github.com/python-poetry/poetry/blob/HEAD/CHANGELOG.md#220---2025-09-14)

[Compare Source](python-poetry/poetry@2.1.4...2.2.0)

##### Added

- **Add support for nesting dependency groups** ([#&#8203;10166](python-poetry/poetry#10166)).
- **Add support for PEP 735 dependency groups** ([#&#8203;10130](python-poetry/poetry#10130)).
- **Add support for PEP 639 license clarity** ([#&#8203;10413](python-poetry/poetry#10413)).
- Add a `--format` option to `poetry show` to alternatively output json format ([#&#8203;10487](python-poetry/poetry#10487)).
- Add official support for Python 3.14 ([#&#8203;10514](python-poetry/poetry#10514)).

##### Changed

- **Normalize dependency group names** ([#&#8203;10387](python-poetry/poetry#10387)).
- Change `installer.no-binary` and `installer.only-binary` so that explicit package names will take precedence over `:all:` ([#&#8203;10278](python-poetry/poetry#10278)).
- Improve log output during `poetry install` when a wheel is built from source ([#&#8203;10404](python-poetry/poetry#10404)).
- Improve error message in case a file lock could not be acquired while cloning a git repository ([#&#8203;10535](python-poetry/poetry#10535)).
- Require `dulwich>=0.24.0` ([#&#8203;10492](python-poetry/poetry#10492)).
- Allow `virtualenv>=20.33` again ([#&#8203;10506](python-poetry/poetry#10506)).
- Allow `findpython>=0.7` ([#&#8203;10510](python-poetry/poetry#10510)).
- Allow `importlib-metadata>=8.7` ([#&#8203;10511](python-poetry/poetry#10511)).

##### Fixed

- Fix an issue where `poetry new` did not create the project structure in an existing empty directory ([#&#8203;10431](python-poetry/poetry#10431)).
- Fix an issue where a dependency that was required for a specific Python version was not installed into an environment of a pre-release Python version ([#&#8203;10516](python-poetry/poetry#10516)).

##### poetry-core ([`2.2.0`](https://github.com/python-poetry/poetry-core/releases/tag/2.2.0))

- Deprecate table values and values that are not valid SPDX expressions for `[project.license]` ([#&#8203;870](python-poetry/poetry-core#870)).
- Fix an issue where explicitly included files that are in `.gitignore` were not included in the distribution ([#&#8203;874](python-poetry/poetry-core#874)).
- Fix an issue where marker operations could result in invalid markers ([#&#8203;875](python-poetry/poetry-core#875)).

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS42MC40IiwidXBkYXRlZEluVmVyIjoiNDEuNjAuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://git.walbeck.it/walbeck-it/docker-python-poetry/pulls/1588
Co-authored-by: renovate-bot <[email protected]>
Co-committed-by: renovate-bot <[email protected]>
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2025
@radoering radoering deleted the update-importlib-metadata branch December 13, 2025 17:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant