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 Apr 4, 2023
1 parent 4febc2c commit 19a0df7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cherrypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"""

try:
import pkg_resources
import importlib
except ImportError:
pass

Expand Down Expand Up @@ -109,7 +109,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, 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
10 changes: 4 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,9 @@ 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')
import pdb
pdb.set_trace()
prj_author = prj_meta['Author']
prj_license = prj_meta['License']
prj_description = prj_meta['Description']
Expand All @@ -54,7 +52,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

0 comments on commit 19a0df7

Please sign in to comment.