summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2022-10-16 18:22:33 -0500
committerGitHub <noreply@github.com>2022-10-16 18:22:33 -0500
commit88bf5f87f36d570c86cf7f39636b573fc52086b7 (patch)
treeff94b7eee8bd2db3fb08ba0083a3d880f5a3deae
parent0f0697dc20ab33c675d9eecb485f41ed26fa70b8 (diff)
parent02f3609cb65280842b06eeeb31096445ee7a9eab (diff)
downloadpastedeploy-git-88bf5f87f36d570c86cf7f39636b573fc52086b7.tar.gz
Merge pull request #37 from Pylons/importlib-metadata
drop setuptools/pkg_resources and replace with importlib.metadata
-rw-r--r--.github/workflows/ci-tests.yml24
-rw-r--r--docs/conf.py8
-rw-r--r--docs/news.rst2
-rw-r--r--setup.cfg4
-rw-r--r--src/paste/deploy/config.py3
-rw-r--r--src/paste/deploy/loadwsgi.py54
-rw-r--r--src/paste/deploy/util.py6
-rw-r--r--tests/__init__.py7
-rw-r--r--tests/fixture.py19
-rw-r--r--tests/test_load_package.py6
-rw-r--r--tox.ini3
11 files changed, 53 insertions, 83 deletions
diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml
index 7ada44c..a7a717d 100644
--- a/.github/workflows/ci-tests.yml
+++ b/.github/workflows/ci-tests.yml
@@ -45,19 +45,19 @@ jobs:
- run: pip install tox
- name: Running tox
run: tox -e py
- # coverage:
- # runs-on: ubuntu-latest
- # name: Validate coverage
- # steps:
- # - uses: actions/checkout@v2
- # - name: Setup python 3.10
- # uses: actions/setup-python@v2
- # with:
- # python-version: "3.10"
- # architecture: x64
+ coverage:
+ runs-on: ubuntu-latest
+ name: Validate coverage
+ steps:
+ - uses: actions/checkout@v2
+ - name: Setup python 3.10
+ uses: actions/setup-python@v2
+ with:
+ python-version: "3.10"
+ architecture: x64
- # - run: pip install tox
- # - run: tox -e py310,coverage
+ - run: pip install tox
+ - run: tox -e py310,coverage
docs:
runs-on: ubuntu-latest
name: Build the documentation
diff --git a/docs/conf.py b/docs/conf.py
index bf4faa8..9e5e04f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -12,7 +12,11 @@
# serve to show the default value.
import datetime
-import pkg_resources
+
+try:
+ import importlib.metadata as importlib_metadata
+except ImportError:
+ import importlib_metadata
import pylons_sphinx_themes
# If your extensions are in another directory, add it here.
@@ -51,7 +55,7 @@ copyright = '2011-%s, Ian Bicking and contributors' % thisyear
# other places throughout the built documents.
#
# The short X.Y version.
-version = pkg_resources.get_distribution('pastedeploy').version
+version = importlib_metadata.distribution('pastedeploy').version
# The full version, including alpha/beta/rc tags.
release = version
diff --git a/docs/news.rst b/docs/news.rst
index 05d8f9f..94deead 100644
--- a/docs/news.rst
+++ b/docs/news.rst
@@ -9,6 +9,8 @@ unreleased
* Fix a broken compatibility shim that would cause the ConfigParser to fail
on Python 3.12 when ``ConfigParser.readfp`` is removed.
+* Drop setuptools dependency and start using ``importlib.metadata`` instead.
+
* Refactor repository into a src folder layout.
2.1.1 (2020-10-12)
diff --git a/setup.cfg b/setup.cfg
index 4d81c86..2b896a7 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = PasteDeploy
-version = 2.1.1
+version = 3.0.dev0
author = Ian Bicking
author_email = pylons-discuss@googlegroups.com
maintainer = Chris Dent
@@ -44,7 +44,7 @@ package_dir =
packages = find:
zip_safe = False
install_requires =
- setuptools
+ importlib-metadata; python_version<"3.8"
include_package_data = True
namespace_packages =
paste
diff --git a/src/paste/deploy/config.py b/src/paste/deploy/config.py
index b174fa0..c9714fe 100644
--- a/src/paste/deploy/config.py
+++ b/src/paste/deploy/config.py
@@ -155,9 +155,6 @@ class ConfigMiddleware:
def __call__(self, environ, start_response):
global wsgilib
if wsgilib is None:
- import pkg_resources
-
- pkg_resources.require('Paste')
from paste import wsgilib
popped_config = None
if 'paste.config' in environ:
diff --git a/src/paste/deploy/loadwsgi.py b/src/paste/deploy/loadwsgi.py
index 482b339..bde8a08 100644
--- a/src/paste/deploy/loadwsgi.py
+++ b/src/paste/deploy/loadwsgi.py
@@ -6,9 +6,7 @@ import re
import sys
from urllib.parse import unquote
-import pkg_resources
-
-from paste.deploy.util import fix_call, lookup_object
+from paste.deploy.util import fix_call, importlib_metadata, lookup_object
__all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig']
@@ -18,14 +16,10 @@ __all__ = ['loadapp', 'loadserver', 'loadfilter', 'appconfig']
############################################################
-def import_string(s):
- ep = pkg_resources.EntryPoint.parse("x=" + s)
- if hasattr(ep, 'resolve'):
- # this is available on setuptools >= 10.2
- return ep.resolve()
- else:
- # this causes a DeprecationWarning on setuptools >= 11.3
- return ep.load(False)
+def find_entry_point(dist, group, name):
+ for entry in dist.entry_points:
+ if entry.name == name and entry.group == group:
+ return entry
def _aslist(obj):
@@ -443,7 +437,7 @@ class ConfigLoader(_Loader):
filter_with = None
if 'require' in local_conf:
for spec in local_conf['require'].split():
- pkg_resources.require(spec)
+ importlib_metadata.distribution(spec)
del local_conf['require']
if section.startswith('filter-app:'):
context = self._filter_app_context(
@@ -532,7 +526,9 @@ class ConfigLoader(_Loader):
raise LookupError("No loader given in section %r" % section)
found_protocol, found_expr = possible[0]
del local_conf[found_protocol]
- value = import_string(found_expr)
+ value = importlib_metadata.EntryPoint(
+ name=None, group=None, value=found_expr
+ ).load()
context = LoaderContext(
value, object_type, found_protocol, global_conf, local_conf, self
)
@@ -649,51 +645,37 @@ class EggLoader(_Loader):
global_conf or {},
{},
self,
- distribution=pkg_resources.get_distribution(self.spec),
+ distribution=importlib_metadata.distribution(self.spec),
entry_point_name=ep_name,
)
def find_egg_entry_point(self, object_type, name=None):
"""
- Returns the (entry_point, protocol) for the with the given
- ``name``.
+ Returns the (entry_point, protocol) for with the given ``name``.
"""
if name is None:
name = 'main'
+ dist = importlib_metadata.distribution(self.spec)
possible = []
for protocol_options in object_type.egg_protocols:
for protocol in protocol_options:
- pkg_resources.require(self.spec)
- entry = pkg_resources.get_entry_info(self.spec, protocol, name)
+ entry = find_entry_point(dist, protocol, name)
if entry is not None:
possible.append((entry.load(), protocol, entry.name))
break
if not possible:
# Better exception
- dist = pkg_resources.get_distribution(self.spec)
raise LookupError(
- "Entry point %r not found in egg %r (dir: %s; protocols: %s; "
- "entry_points: %s)"
+ "Entry point %r not found in egg %r (protocols: %s; entry_points: %s)"
% (
name,
self.spec,
- dist.location,
', '.join(_flatten(object_type.egg_protocols)),
', '.join(
- _flatten(
- [
- list(
- (
- pkg_resources.get_entry_info(
- self.spec, prot, name
- )
- or {}
- ).keys()
- )
- for prot in protocol_options
- ]
- or '(no entry points)'
- )
+ str(entry)
+ for prot in protocol_options
+ for entry in [find_entry_point(dist, prot, name)]
+ if entry
),
)
)
diff --git a/src/paste/deploy/util.py b/src/paste/deploy/util.py
index 6bd6132..a9c20d6 100644
--- a/src/paste/deploy/util.py
+++ b/src/paste/deploy/util.py
@@ -3,6 +3,12 @@
import inspect
import sys
+try:
+ import importlib.metadata as importlib_metadata # noqa F401
+except ImportError: # pragma: no cover
+ # bw-compat shim for py37
+ import importlib_metadata # noqa F401
+
def fix_type_error(exc_info, callable, varargs, kwargs):
"""
diff --git a/tests/__init__.py b/tests/__init__.py
index 555181c..8ba6060 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -17,12 +17,11 @@ if not os.path.exists(egg_info_dir):
sys.path.append(os.path.dirname(egg_info_dir))
-import pkg_resources # noqa E402
+from paste.deploy.util import importlib_metadata # noqa E402
# Make absolutely sure we're testing *this* package, not
# some other installed package
-pkg_resources.require('PasteDeploy')
+importlib_metadata.distribution('PasteDeploy')
# ensure FakeApp is available for use by tests
-pkg_resources.working_set.add_entry(os.path.dirname(egg_info_dir))
-pkg_resources.require('FakeApp')
+importlib_metadata.distribution('FakeApp')
diff --git a/tests/fixture.py b/tests/fixture.py
deleted file mode 100644
index 6d92260..0000000
--- a/tests/fixture.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import os
-import shutil
-import sys
-
-test_dir = os.path.dirname(__file__)
-egg_info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO')
-info_dir = os.path.join(test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info')
-if not os.path.exists(egg_info_dir):
- try:
- os.symlink(info_dir, egg_info_dir)
- except Exception:
- shutil.copytree(info_dir, egg_info_dir)
-
-sys.path.append(os.path.dirname(egg_info_dir))
-
-import pkg_resources # noqa E402
-
-pkg_resources.working_set.add_entry(os.path.dirname(egg_info_dir))
-pkg_resources.require('FakeApp')
diff --git a/tests/test_load_package.py b/tests/test_load_package.py
index bdd6e3f..b0d5031 100644
--- a/tests/test_load_package.py
+++ b/tests/test_load_package.py
@@ -1,10 +1,10 @@
from pprint import pprint
import sys
-import pkg_resources
-
def test_load_package():
+ from paste.deploy.util import importlib_metadata
+
print('Path:')
pprint(sys.path)
- print(pkg_resources.require('FakeApp'))
+ importlib_metadata.distribution('FakeApp')
diff --git a/tox.ini b/tox.ini
index 18f23f6..4b9996b 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,8 +17,7 @@ setenv =
[testenv:coverage]
commands =
coverage combine
- coverage xml
- coverage report --fail-under=100
+ coverage report
deps =
coverage
setenv =