Skip to content

Commit

Permalink
GitHub Issue cherrypy#1973: RFE: Replace use of pkg_resources with im…
Browse files Browse the repository at this point in the history
…portlib.metadata

Replaces references to pkg_resources with importlib.metadata
Latest setuptools reports: DeprecationWarning: pkg_resources is deprecated as an API
  • Loading branch information
radez committed Dec 21, 2023
1 parent 8946187 commit abb5e5e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
11 changes: 8 additions & 3 deletions cherrypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@
"""

try:
import pkg_resources
import importlib.metadata as importlib_metadata
except ImportError:
pass
# fall back for python <= 3.7
# can simply pass when py 3.6/3.7 no longer supported
try:
import importlib_metadata
except ImportError:
pass

from threading import local as _local

Expand Down Expand Up @@ -109,7 +114,7 @@


try:
__version__ = pkg_resources.require('cherrypy')[0].version
__version__ = importlib_metadata.version('cherrypy')
except Exception:
__version__ = 'unknown'

Expand Down
5 changes: 2 additions & 3 deletions cherrypy/test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,10 @@ def start(self, imports=None):
```
['-c',
"__requires__ = 'CherryPy'; \
import pkg_resources, re, sys; \
import importlib.metadata, re, sys; \
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]); \
sys.exit(\
pkg_resources.load_entry_point(\
'CherryPy', 'console_scripts', 'cherryd')())"]
importlib.metadata.distribution('cherrypy').entry_points[0])"]
```
doesn't work as it's impossible to reconstruct the `-c`'s contents.
Expand Down
8 changes: 2 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from email import message_from_string
import importlib
import pkg_resources
import sys

assert sys.version_info > (3, 5), 'Python 3 required to build docs'
Expand Down Expand Up @@ -43,9 +41,7 @@ def get_supported_pythons(classifiers):

custom_sphinx_theme = try_import('alabaster')

prj_dist = pkg_resources.get_distribution('cherrypy')
prj_pkg_info = prj_dist.get_metadata(prj_dist.PKG_INFO)
prj_meta = message_from_string(prj_pkg_info)
prj_meta = importlib.metadata.metadata('cherrypy')
prj_author = prj_meta['Author']
prj_license = prj_meta['License']
prj_description = prj_meta['Description']
Expand All @@ -54,7 +50,7 @@ def get_supported_pythons(classifiers):
lambda v: '.'.join(map(str, v)), prj_py_ver_range
)

project = prj_dist.project_name
project = prj_meta['Name']

github_url = 'https://github.com'
github_repo_org = project.lower()
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
'sphinxcontrib-apidoc>=0.3.0',
'rst.linker>=1.11',
'jaraco.packaging>=3.2',
'setuptools',
],
'json': ['simplejson'],
'routes_dispatcher': ['routes>=2.3.1'],
Expand Down

0 comments on commit abb5e5e

Please sign in to comment.