Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: parsing package names & versions from METADATA file instead of dist-info directory #476

Closed
lada-gagina opened this issue Nov 1, 2023 · 1 comment
Labels
question Further information is requested

Comments

@lada-gagina
Copy link

lada-gagina commented Nov 1, 2023

Hello!
Sorry if that’s a stupid question, please direct me if it should be asked in some different place.
Python 3.12 has dropped pkg_resources module which was providing access to installed packages info. The alternative is importlib.metadata.
I see that the latter works differently: it seems to use METADATA file inside dist-info dir, instead of parsing the package’s name and version directly from dist-info dir’s name. I see it’s most probably intended, but why does it work this way now?

@jaraco
Copy link
Member

jaraco commented Dec 1, 2023

Hi Lada-Gagina. I'm happy to answer questions. I do only check Github intermittently, so that's why there's sometimes a delay.

Although there are some cases where pkg_resources loads the version from the filename, there are other places where it loads the version from the metadata.

There are some cases where a version number isn't available or accurate in the metadata file, so importlib metadata attempts to rely on the metadata as the canonical source for all metadata, including version. Another reason for not relying on the filename is that the Python import system offers extensible interfaces for package providers such that the packages and their metadata can exist without a file system at all, where the metadata could be stored in a database for example.

If I had to guess, I expect the reason that pkg_resources relied on the version in the filename was for efficiency - if one can assume the version is in the filename, it can save many stat and read operations to extract the version from the metadata. Unfortunately, that's just not a reliable source of truth, so it's no longer used.

I hope that answers the question. I'll close this for now, but feel free to follow-up if needed.

@jaraco jaraco closed this as completed Dec 1, 2023
@jaraco jaraco added the question Further information is requested label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants