summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2021-10-26 18:21:06 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-10-26 18:21:06 +0000
commit87c102ca4612109db54cdf95e7f7a044e087d25a (patch)
tree32fb8e3a053b3af62018c3dd1eb5f554661486ed
parent5feab89c60453b9fdf45e11e8185a04b5f44e150 (diff)
parent46e7a5d330facf5f01c14133ecc18f21b6e9114c (diff)
downloadmako-87c102ca4612109db54cdf95e7f7a044e087d25a.tar.gz
Merge "Replace the use of pkg_resources with the importlib library." into main
-rw-r--r--doc/build/caching.rst2
-rw-r--r--doc/build/unreleased/pgk_resources.rst5
-rw-r--r--mako/compat.py15
-rw-r--r--mako/util.py20
-rw-r--r--setup.cfg1
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():
diff --git a/setup.cfg b/setup.cfg
index f9d0978..ea50c03 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -35,6 +35,7 @@ zip_safe = false
install_requires =
MarkupSafe >= 0.9.2
+ importlib-metadata;python_version<"3.8"
[options.packages.find]
exclude =