Skip to content

Commit

Permalink
Merge pull request #3748 from Pylons/replace-pkg-resoures-dottednamer…
Browse files Browse the repository at this point in the history
…esolver

remove pkg_resources from DottedNameResolver
  • Loading branch information
mmerickel authored Feb 5, 2024
2 parents b2457bb + 4fbbf1f commit a6fe1a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
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

0 comments on commit a6fe1a1

Please sign in to comment.