From 72df1c58f9d9901de136ca9b81e9724a5eb8ef0a Mon Sep 17 00:00:00 2001 From: Dan Radez Date: Tue, 4 Apr 2023 09:39:44 -0400 Subject: [PATCH] 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 --- cherrypy/__init__.py | 4 ++-- cherrypy/test/helper.py | 5 ++--- docs/conf.py | 8 ++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cherrypy/__init__.py b/cherrypy/__init__.py index 8e27c812..f329aa73 100644 --- a/cherrypy/__init__.py +++ b/cherrypy/__init__.py @@ -57,7 +57,7 @@ These API's are described in the `CherryPy specification """ try: - import pkg_resources + import importlib except ImportError: pass @@ -109,7 +109,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..983f6be4 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, 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 480edef4..64b2028a 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(v), prj_py_ver_range ) -project = prj_dist.project_name +project = prj_meta['Name'] github_url = 'https://github.com' github_repo_org = project.lower() -- 2.40.0