Repository navigation
Prefer valid distributions when collecting entry points - #536
binggao1230 wants to merge 1 commit into
Conversation
|
I've not tested this but I'm not convinced it will actually work in all cases. Our reason for this is that thanks to package upgrades and removals we'll end up with eg This is discovered as a distribution, and because |
|
I take that back, latest importlib_metadata has different behaviour and correctly raises an exception. |
|
I must admit I don't understand the reasoning behind returning invalid distributions at all: if some empty directories that look like a dist but have no content are found, why return them at all? |
|
I agree that globally dropping invalid distributions is the cleaner end state if the project wants that behavior. I kept this PR narrower for two reasons:
So this patch is conservative rather than philosophical: it avoids letting an invalid duplicate shadow a valid package, but does not decide whether invalid dist-info directories should disappear from discovery everywhere. If you prefer the broader policy, I can rework it in that direction. |
It's because the presence of the directory implies presence of a package at that version. The distribution is there even though it has no metadata. One could theoretically put a 'other-metadata.txt' in the -dist-info directory, and that would be queryable using this API. The API is trying to reflect the reality of the situation and be lenient to corruption or future evolution or extension. |
|
In #550, I implemented an even narrower approach, which was to implement an imperfect sorting heuristic to paper over the most common case where a newer version replaces an older version but the older version metadata isn't cleaned up properly. That approach will help the common case, but will fail to help in the case where:
It almost makes me wonder if the sorting should instead sort by timestamp on the directory, which would more reliably reflect "newest". |
| unique: dict[str, Distribution] = {} | ||
| for dist in dists: | ||
| name = dist._normalized_name | ||
| if name not in unique: | ||
| unique[name] = dist | ||
| elif not has_metadata(unique[name]) and has_metadata(dist): | ||
| unique[name] = dist | ||
| return unique.values() |
There was a problem hiding this comment.
This approach undermines the intent of _unique, which was to produce a lazily-generated iterable of distributions. By constructing the dict, it changes the shape of the wrapper. I agree this proposal does what's intended; I'm just uneasy with how it (necessarily) interferes with the flow at this stage.
|
I'm now reconsidering the approach in #550 and wondering if instead we shouldn't take the |
|
Thanks for taking this forward in #553. That version addresses the same failure while preserving the lazy |
Fixes #534
Summary
entry_points()that replaces an invalid/empty dist-info entry with a later valid distribution of the same normalized namefoo.dist-infoappears before a valid one with entry pointsTests
Without the fix, the new test fails with
KeyError: 'main'.AI assistance was used under my direction.