Skip to content

Commit

Permalink
Merge pull request cherrypy#2011 from radez/issue1973-2
Browse files Browse the repository at this point in the history
This patch adds a dependency on `importlib_metadata` in runtime conditionally, when `importlib.metadata` is unavailable.
It also starts using it as a fallback in the Sphinx config and drops unnecessary import suppression from the fallback branch.
  • Loading branch information
webknjaz committed Dec 26, 2023
2 parents c3961da + 8abb544 commit 30d9a14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 2 additions & 5 deletions cherrypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@
import importlib.metadata as importlib_metadata
except ImportError:
# 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
# This try/except can be removed with py <= 3.7 support
import importlib_metadata

from threading import local as _local

Expand Down
9 changes: 8 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
import importlib
import sys

try:
import importlib.metadata as importlib_metadata
except ImportError:
# fall back for python <= 3.7
# This try/except can be removed with py <= 3.7 support
import importlib_metadata

assert sys.version_info > (3, 5), 'Python 3 required to build docs'


Expand All @@ -41,7 +48,7 @@ def get_supported_pythons(classifiers):

custom_sphinx_theme = try_import('alabaster')

prj_meta = importlib.metadata.metadata('cherrypy')
prj_meta = importlib_metadata.metadata('cherrypy')
prj_author = prj_meta['Author']
prj_license = prj_meta['License']
prj_description = prj_meta['Description']
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'more_itertools',
'zc.lockfile',
'jaraco.collections',
'importlib-metadata; python_version<="3.7"',
],
extras_require={
'docs': [
Expand Down

0 comments on commit 30d9a14

Please sign in to comment.