GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Prefer valid distributions when collecting entry points by binggao1230 · Pull Request #536 · python/importlib_metadata 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I take that back, latest importlib_metadata has different behaviour and correctly raises an exception. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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". |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| 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.
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm now reconsidering the approach in #550 and wondering if instead we shouldn't take the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for taking this forward in #553. That version addresses the same failure while preserving the lazy |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
entry_points doesn't handle empty .dist-info files well
There was an error while loading. Please reload this page.