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

remove pkg_resources from DottedNameResolver #3748

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Features

See https://github.com/Pylons/pyramid/pull/3745

- Replace usage of ``pkg_resources`` in ``pyramid.path.DottedNameResolver``.
See https://github.com/Pylons/pyramid/pull/3748

Bug Fixes
---------

Expand Down
22 changes: 14 additions & 8 deletions src/pyramid/path.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functools
from importlib import import_module
from importlib.machinery import SOURCE_SUFFIXES
import os
import pkg_resources
Expand Down Expand Up @@ -344,14 +346,18 @@ def _pkg_resources_style(self, value, package):
value = package.__name__
else:
value = package.__name__ + value
# Calling EntryPoint.load with an argument is deprecated.
# See https://pythonhosted.org/setuptools/history.html#id8
ep = pkg_resources.EntryPoint.parse('x=%s' % value)
if hasattr(ep, 'resolve'):
# setuptools>=10.2
return ep.resolve() # pragma: NO COVER
else:
return ep.load(False) # pragma: NO COVER
# logic below is similar to importlib.metadata.EntryPoint.load()
module = value
attrs = []
parts = value.split(':', 1)
if len(parts) == 2:
module, attrs = parts
attrs = attrs.split('.')
module = import_module(module)
try:
return functools.reduce(getattr, attrs, module)
except AttributeError as ex:
raise ImportError(str(ex))

def _zope_dottedname_style(self, value, package):
"""package.module.attr style"""
Expand Down