|
|
c556e0f |
commit 40969c2e254c39d00243bb1b55145dc779c42316
|
|
|
c556e0f |
Author: Dan Radez <dradez@redhat.com>
|
|
|
c556e0f |
Date: Tue Apr 4 09:39:44 2023 -0400
|
|
|
e291dac |
|
|
|
c556e0f |
GitHub Issue #1973: RFE: Replace use of pkg_resources with importlib.metadata
|
|
|
c556e0f |
|
|
|
c556e0f |
Replaces references to pkg_resources with importlib.metadata
|
|
|
c556e0f |
Latest setuptools reports: DeprecationWarning: pkg_resources is deprecated as an API
|
|
|
e291dac |
|
|
|
e291dac |
diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py
|
|
|
c556e0f |
index 8e27c812..50e715a9 100644
|
|
|
e291dac |
--- a/cherrypy/__init__.py
|
|
|
e291dac |
+++ b/cherrypy/__init__.py
|
|
|
c556e0f |
@@ -57,9 +57,14 @@ These API's are described in the `CherryPy specification
|
|
|
e291dac |
"""
|
|
|
e291dac |
|
|
|
e291dac |
try:
|
|
|
e291dac |
- import pkg_resources
|
|
|
c556e0f |
+ import importlib.metadata as importlib_metadata
|
|
|
e291dac |
except ImportError:
|
|
|
c556e0f |
- pass
|
|
|
c556e0f |
+ # fall back for python <= 3.7
|
|
|
c556e0f |
+ # can simply pass when py 3.6/3.7 no longer supported
|
|
|
c556e0f |
+ try:
|
|
|
c556e0f |
+ import importlib_metadata
|
|
|
c556e0f |
+ except ImportError:
|
|
|
c556e0f |
+ pass
|
|
|
e291dac |
|
|
|
c556e0f |
from threading import local as _local
|
|
|
c556e0f |
|
|
|
c556e0f |
@@ -109,7 +114,7 @@ tree = _cptree.Tree()
|
|
|
e291dac |
|
|
|
e291dac |
|
|
|
e291dac |
try:
|
|
|
e291dac |
- __version__ = pkg_resources.require('cherrypy')[0].version
|
|
|
c556e0f |
+ __version__ = importlib_metadata.version('cherrypy')
|
|
|
e291dac |
except Exception:
|
|
|
e291dac |
__version__ = 'unknown'
|
|
|
e291dac |
|
|
|
e291dac |
diff --git a/cherrypy/test/helper.py b/cherrypy/test/helper.py
|
|
|
c556e0f |
index cae49533..9b7cb274 100644
|
|
|
e291dac |
--- a/cherrypy/test/helper.py
|
|
|
e291dac |
+++ b/cherrypy/test/helper.py
|
|
|
e291dac |
@@ -461,11 +461,10 @@ server.ssl_private_key: r'%s'
|
|
|
e291dac |
```
|
|
|
e291dac |
['-c',
|
|
|
e291dac |
"__requires__ = 'CherryPy'; \
|
|
|
e291dac |
- import pkg_resources, re, sys; \
|
|
|
c556e0f |
+ import importlib.metadata, re, sys; \
|
|
|
e291dac |
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]); \
|
|
|
e291dac |
sys.exit(\
|
|
|
e291dac |
- pkg_resources.load_entry_point(\
|
|
|
e291dac |
- 'CherryPy', 'console_scripts', 'cherryd')())"]
|
|
|
e291dac |
+ importlib.metadata.distribution('cherrypy').entry_points[0])"]
|
|
|
e291dac |
```
|
|
|
e291dac |
|
|
|
e291dac |
doesn't work as it's impossible to reconstruct the `-c`'s contents.
|
|
|
e291dac |
diff --git a/docs/conf.py b/docs/conf.py
|
|
|
c556e0f |
index a45e632d..4a0ceb54 100644
|
|
|
e291dac |
--- a/docs/conf.py
|
|
|
e291dac |
+++ b/docs/conf.py
|
|
|
e291dac |
@@ -13,9 +13,7 @@
|
|
|
e291dac |
# All configuration values have a default; values that are commented out
|
|
|
e291dac |
# serve to show the default.
|
|
|
e291dac |
|
|
|
e291dac |
-from email import message_from_string
|
|
|
e291dac |
import importlib
|
|
|
e291dac |
-import pkg_resources
|
|
|
e291dac |
import sys
|
|
|
e291dac |
|
|
|
e291dac |
assert sys.version_info > (3, 5), 'Python 3 required to build docs'
|
|
|
e291dac |
@@ -43,9 +41,7 @@ def get_supported_pythons(classifiers):
|
|
|
e291dac |
|
|
|
e291dac |
custom_sphinx_theme = try_import('alabaster')
|
|
|
e291dac |
|
|
|
e291dac |
-prj_dist = pkg_resources.get_distribution('cherrypy')
|
|
|
e291dac |
-prj_pkg_info = prj_dist.get_metadata(prj_dist.PKG_INFO)
|
|
|
e291dac |
-prj_meta = message_from_string(prj_pkg_info)
|
|
|
e291dac |
+prj_meta = importlib.metadata.metadata('cherrypy')
|
|
|
e291dac |
prj_author = prj_meta['Author']
|
|
|
e291dac |
prj_license = prj_meta['License']
|
|
|
e291dac |
prj_description = prj_meta['Description']
|
|
|
e291dac |
@@ -54,7 +50,7 @@ prj_py_min_supported, prj_py_max_supported = map(
|
|
|
c556e0f |
lambda v: '.'.join(map(str, v)), prj_py_ver_range
|
|
|
e291dac |
)
|
|
|
e291dac |
|
|
|
e291dac |
-project = prj_dist.project_name
|
|
|
e291dac |
+project = prj_meta['Name']
|
|
|
e291dac |
|
|
|
e291dac |
github_url = 'https://github.com'
|
|
|
e291dac |
github_repo_org = project.lower()
|