commit 40969c2e254c39d00243bb1b55145dc779c42316 Author: Dan Radez Date: Tue Apr 4 09:39:44 2023 -0400 GitHub Issue #1973: RFE: Replace use of pkg_resources with importlib.metadata Replaces references to pkg_resources with importlib.metadata Latest setuptools reports: DeprecationWarning: pkg_resources is deprecated as an API diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py index 8e27c812..50e715a9 100644 --- a/cherrypy/__init__.py +++ b/cherrypy/__init__.py @@ -57,9 +57,14 @@ These API's are described in the `CherryPy specification """ 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 @@ -109,7 +114,7 @@ tree = _cptree.Tree() try: - __version__ = pkg_resources.require('cherrypy')[0].version + __version__ = importlib_metadata.version('cherrypy') except Exception: __version__ = 'unknown' diff --git a/cherrypy/test/helper.py b/cherrypy/test/helper.py index cae49533..9b7cb274 100644 --- a/cherrypy/test/helper.py +++ b/cherrypy/test/helper.py @@ -461,11 +461,10 @@ server.ssl_private_key: r'%s' ``` ['-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. diff --git a/docs/conf.py b/docs/conf.py index a45e632d..4a0ceb54 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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' @@ -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'] @@ -54,7 +50,7 @@ prj_py_min_supported, prj_py_max_supported = map( 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()