-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Replace pkg_resources with importlib_metadata #7413
Comments
Regarding jazzband/pathlib2#56: Summary: pathlib2.Path stores path parts as bytes. On Python 2 when provided a Impact: Medium/Low. Internally in pip we do not deal with Mitigation: We can patch |
I'm on board for this. This seems like the least-worst option here. |
I’m wondering, are there behavioural differences between |
+1 on this option. Adding a load more vendored code just to support Python 2 is not a route I want to go down, TBH. |
|
I briefly looked into this and immediately hit a roadblock. pip checks how a distribution is installed by checking the |
@jaraco ⬆️ |
I think gitlab/python-devs/importlib_metadata#23 more or less covers the problem. pip will also need to read In general I think pip needs a to be able to reliably access arbitrary files in |
It looks like |
Yup, |
Writing up my personal thoughts on this (by suggestion of @pradyunsg) since I don’t expect myself to work on this personally for a while, but the plan (from what I can tell) is reletively straightforward and anyone interested in this can try to carry it out. So the plan is to use
I believe this work would be valuable even if it happens after we drop Python 2. It is extremely tedious to rewrite all the |
I'd recommend moving entirely to Also, I'm happy to help with this effort by providing technical support on the implementation, as long as someone can lead the effort. |
@uranusjr With the above PRs, is there anything more to do here, given that we're using importlib.metadata on 3.11+? pip/src/pip/_internal/metadata/__init__.py Lines 32 to 41 in 1ab22ee
|
Yeah I think everything is in place, the only thing we need now is for time to take over. |
What's the problem this feature will solve?
Currently, pip uses a vendored version of
pkg_resources
in several places.pkg_resources has a few downsides for our use cases, including:
sys.path
on import (Avoid full path enumeration on import of setuptools or pkg_resources? setuptools#510), when we may only need it for a subset of those directoriesMETADATA
files in site-packages preventing pip from startingDescribe the solution you'd like
Replace
pkg_resources
withimportlib.metadata
(via theimportlib-metadata
backport for Python < 3.8).Our current usages for
pkg_resources
are:build_env.BuildEnvironment
: identify the set of packages available/conflicting in the isolated environment directoriesreq.req_install.InstallRequirement
: locate an already-installed packagecommands.search
,commands.show
: iterate over the set of installed packages and access metadatawheel
:A combination of
importlib_metadata
andpackaging
can satisfy these requirements:importlib.metadata.distributions(path=["dir1", "dir2"])
then comparison of the version usingpackaging.specifiers.SpecifierSet
importlib.metadata.distribution("package_name")
orimportlib.metadata.distributions(path=["..."], name="package_name")
[d.metadata["..."] for d in importlib.metadata.distributions()]
importlib.metadata.Distribution.at(info_dir).entry_points
next(importlib.metadata.distributions(path=["..."])).read_text("WHEEL")
packaging.utils.canonicalize_name
, etcAs a vendored library,
importlib-metadata
would have the following characteristics:contextlib2
, which we already vendorpathlib2
- we have looked at for tests. There is one issue we need to investigate the impact of: Unusable on Windows/Python2.7 with unicode paths jazzband/pathlib2#56 - MIT licensed, pure Python with no dependenciesconfigparser
-configparser
backport - MIT licensed, pure Python with no dependencieszipp
for making thezipfile
modulePath
-aware - MIT licensed, pure Python with no dependenciesAlternative Solutions
pkg_resources
- this approach has the downsides mentioned aboveSee also
The text was updated successfully, but these errors were encountered: