-
Notifications
You must be signed in to change notification settings - Fork 887
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
pkg_resources is deprecated #3731
Comments
The issue is around I'm not really aware of places that importlib.metadata would be helpful in pyramid but those have been very easy to replace in any package where I've done it to drop setuptools for that purpose. |
It may be possible to override importlib machinery? A custom Do we want to monkeypatch the import machinery, though? It seems to go against Pyramid's MO of everything contained within a registry and discouraging threadlocals. Now's the time to break from that, as all projects will have to rewrite their As a counterpoint, however, maintainers will by default follow the migration guide and expect it to just work. |
I’m gonna be honest I don’t really know what to do about this. It’s been in the back of my mind for a long time and just haven’t seen a path forward.
Am I missing an option? |
As a compromise between one and two, we could keep override support for static views but drop support for global overrides. Static overrides I think are necessary, as you often have static assets stored outside of your Python package, but I'm not convinced how useful it is outside of that.. Perhaps even actively harmful: Can you imagine trying to debug why your app is loading a resource that is not the one in the package, all because of a single To ease the transition, we could have a |
The override feature is very useful because it allows some libraries to easily provide tweaks. For example pypi itself used it (not sure if still) to open source most of their ui while keeping parts of it closed because they were owned by the graphic designer. The override allowed a simple theme concept for them. Also as I said before it’s expected to work for all of the templating libraries for a similar reason. I guess my point is that it’s definitely not there just for static views. |
I'm genuinely at a loss how to deal with this issue. I want to do something to make pkg_resources optional but it's so integral to a some core apis that currently expect a threadlocal place to do a lookup. I think we'd have to make the asset resolution apis work "correctly" without pkg_resources, and then offer an extra api to opt-in to binding the data to pkg_resources if someone wants it. Working correctly is the challenge there - basically it means we'd do some form of asset lookup / registry ourselves that can obey |
We'd then update other libraries like pyramid_jinja2 and pyramid_mako to use whatever API instead. Right now pyramid_jinja2 uses Of course one option is to just make things like |
I have removed the easy spots in #3748 and #3749. Down to 4 locations that are impacted:
Ultimately the focus is:
|
Related, I opened this conversation with importlib_resources after diving into this a bit. |
This isn't a blocker, it'd just be nice if Pyramid could support propagating asset overrides into importlib.resources. Pyramid should offer its own apis (it does, AssetResolver), that work properly without those dependencies, and that's the focus here - try to get Pyramid to work internally without pkg_resources doing all the work for it. That means a new impl will need to use |
Just an observation, but the project seems to be in a transitional phase and stuff is spread out across pyproject.toml, setup.py and setup.cfg which is quite confusing. But Pyramid being an older project that totally makes sense. My guess is that eventually the setup.py and setup.cfg will be dropped. |
It's true we will at some point port most of our project metadata into |
As of setuptools v67.5.0, a deprecation warning is raised when importing pkg_resources:
Apparently this has been replaced by importlib.resources and importlib.metadata, which is available since Python 3.7, as well as packaging.
This may be fairly tricky to remove, as
src/pyramid/config/assets.py
digs pretty deep into the pkg_resources API, namely it registersPackageOverrides
withpkg_resources.register_loader_type
. However I can't figure out why this call is necessary, I can't find where this loader would be used—Maybe something to do withAssetResolver
?The other issue is that pkg_resources would unzip the whole package into a tmp directory when calling
resource_filename
, whereas importlib just extracts that single file.pyramid.path.package_path
depends on this behavior. Possible solutions:pyramid.path.package_path
, and by extensionpramid.path.caller_path
,pyramid.asset.asset_spec_from_abspath
, andpyramid.resource.resource_path_from_abspath
.pyramid.path.package_path
and it's dependents don't work with zip files (or returning zip "path")The text was updated successfully, but these errors were encountered: