Skip to content

Commit

Permalink
Emit a warning when an older version of importlib_metadata is detecte…
Browse files Browse the repository at this point in the history
…d to give users better guidance when this condition is present. Ref #3452.
  • Loading branch information
jaraco committed Jul 14, 2022
1 parent 03da59c commit 565c67a
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions setuptools/_importlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def disable_importlib_metadata_finder(metadata):
Ensure importlib_metadata doesn't provide older, incompatible
Distributions.
Workaround for #3102 and #3452.
Workaround for #3102.
"""
try:
import importlib_metadata
Expand Down Expand Up @@ -34,13 +34,38 @@ def disable_importlib_metadata_finder(metadata):
sys.meta_path.remove(item)


def check_old_importlib_metadata(metadata):
"""
Warn the user if an old importlib_metadata is present and might
cause problems.
Workaround for #3452. Remove this check after 2022-12-31.
"""
try:
version = metadata.version('importlib_metadata')
parsed = tuple(map(int, version.split('.')))
except Exception:
return

if parsed > (4, 3):
return

msg = (
"`importlib_metadata` version is incompatible with the stdlib "
"importlib.metadata and may cause problems if plugins import "
"importlib_metadata. See pypa/setuptools#3452 for details. "
"Consider updating to importlib_metadata 4.3 or later."
)
import warnings
warnings.warn(msg)


if sys.version_info < (3, 10):
from setuptools.extern import importlib_metadata as metadata
disable_importlib_metadata_finder(metadata)
else:
import importlib.metadata as metadata # noqa: F401


disable_importlib_metadata_finder(metadata)
check_old_importlib_metadata(metadata)


if sys.version_info < (3, 9):
Expand Down

0 comments on commit 565c67a

Please sign in to comment.