diff options
| author | Michael Merickel <michael@merickel.org> | 2024-02-04 22:32:05 -0700 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2024-02-04 22:35:57 -0700 |
| commit | 4fbbf1f9f47f56d7619c8c4a8cc2d03a59668ac0 (patch) | |
| tree | ce71164fc5fdec6e389c3d678b7deea5846b2ee1 /src | |
| parent | b2457bba372aead8d66444c233e4d0c48be191a2 (diff) | |
| download | pyramid-4fbbf1f9f47f56d7619c8c4a8cc2d03a59668ac0.tar.gz pyramid-4fbbf1f9f47f56d7619c8c4a8cc2d03a59668ac0.tar.bz2 pyramid-4fbbf1f9f47f56d7619c8c4a8cc2d03a59668ac0.zip | |
remove pkg_resources from DottedNameResolver
Diffstat (limited to 'src')
| -rw-r--r-- | src/pyramid/path.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/pyramid/path.py b/src/pyramid/path.py index a5b7ad212..160d97abe 100644 --- a/src/pyramid/path.py +++ b/src/pyramid/path.py @@ -1,3 +1,5 @@ +import functools +from importlib import import_module from importlib.machinery import SOURCE_SUFFIXES import os import pkg_resources @@ -344,14 +346,18 @@ class DottedNameResolver(Resolver): 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""" |
