diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-10-25 22:04:35 +0200 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2021-10-25 22:04:35 +0200 |
commit | 46e7a5d330facf5f01c14133ecc18f21b6e9114c (patch) | |
tree | 5d789bedd789bb76d8d6782936bbe89d40788665 | |
parent | 6055be01a1357ec3c13937c3aab28360b5e80ea3 (diff) | |
download | mako-46e7a5d330facf5f01c14133ecc18f21b6e9114c.tar.gz |
Replace the use of pkg_resources with the importlib library.
Change-Id: Iafb96d53196ff74c98f2fbc7caf2eb8fbdc70029
-rw-r--r-- | doc/build/caching.rst | 2 | ||||
-rw-r--r-- | doc/build/unreleased/pgk_resources.rst | 5 | ||||
-rw-r--r-- | mako/compat.py | 15 | ||||
-rw-r--r-- | mako/util.py | 20 | ||||
-rw-r--r-- | setup.cfg | 1 |
5 files changed, 33 insertions, 10 deletions
diff --git a/doc/build/caching.rst b/doc/build/caching.rst index bfe4f41..9f63750 100644 --- a/doc/build/caching.rst +++ b/doc/build/caching.rst @@ -284,7 +284,7 @@ using a :class:`.CacheImpl` subclass. This class implements the rudimental methods Mako needs to implement the caching API. Mako includes the :class:`.BeakerCacheImpl` class to provide the default implementation. A :class:`.CacheImpl` class -is acquired by Mako using a ``pkg_resources`` entrypoint, using +is acquired by Mako using a ``importlib.metatada`` entrypoint, using the name given as the ``cache_impl`` argument to :class:`.Template` or :class:`.TemplateLookup`. This entry point can be installed via the standard `setuptools`/``setup()`` procedure, underneath diff --git a/doc/build/unreleased/pgk_resources.rst b/doc/build/unreleased/pgk_resources.rst new file mode 100644 index 0000000..27c74d6 --- /dev/null +++ b/doc/build/unreleased/pgk_resources.rst @@ -0,0 +1,5 @@ +.. change:: + :tags: setup + + Replaced the use of ``pkg_resources`` with the ``importlib`` library. + For Python < 3.8 the library ``importlib_metadata`` is used. diff --git a/mako/compat.py b/mako/compat.py index 852d759..5ffb593 100644 --- a/mako/compat.py +++ b/mako/compat.py @@ -11,6 +11,7 @@ import sys win32 = sys.platform.startswith("win") pypy = hasattr(sys, "pypy_version_info") +py38 = sys.version_info >= (3, 8) ArgSpec = collections.namedtuple( "ArgSpec", ["args", "varargs", "keywords", "defaults"] @@ -59,3 +60,17 @@ def exception_as(): def exception_name(exc): return exc.__class__.__name__ + + +if py38: + from importlib import metadata as importlib_metadata +else: + import importlib_metadata # noqa + + +def importlib_metadata_get(group): + ep = importlib_metadata.entry_points() + if hasattr(ep, "select"): + return ep.select(group=group) + else: + return ep.get(group, ()) diff --git a/mako/util.py b/mako/util.py index 952655c..74c8b9e 100644 --- a/mako/util.py +++ b/mako/util.py @@ -11,6 +11,8 @@ import os import re import timeit +from .compat import importlib_metadata_get + def update_wrapper(decorated, fn): decorated.__wrapped__ = fn @@ -26,17 +28,17 @@ class PluginLoader: def load(self, name): if name in self.impls: return self.impls[name]() - import pkg_resources - for impl in pkg_resources.iter_entry_points(self.group, name): - self.impls[name] = impl.load - return impl.load() - else: - from mako import exceptions + for impl in importlib_metadata_get(self.group): + if impl.name == name: + self.impls[name] = impl.load + return impl.load() - raise exceptions.RuntimeException( - "Can't load plugin %s %s" % (self.group, name) - ) + from mako import exceptions + + raise exceptions.RuntimeException( + "Can't load plugin %s %s" % (self.group, name) + ) def register(self, name, modulepath, objname): def load(): @@ -35,6 +35,7 @@ zip_safe = false install_requires = MarkupSafe >= 0.9.2 + importlib-metadata;python_version<"3.8" [options.packages.find] exclude = |