Skip to content

Commit

Permalink
Prevent vendored importlib_metadata from loading distributions from o…
Browse files Browse the repository at this point in the history
…lder importlib_metadata. Fixes #3102.
  • Loading branch information
jaraco committed Feb 15, 2022
1 parent abbaacc commit 4819690
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/3102.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent vendored importlib_metadata from loading distributions from older importlib_metadata.
23 changes: 23 additions & 0 deletions setuptools/_importlib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import sys


def disable_importlib_metadata_finder(metadata):
"""
Ensure importlib_metadata doesn't provide older, incompatible
Distributions.
Workaround for #3102.
"""
try:
import importlib_metadata
except ImportError:
return
if importlib_metadata is metadata:
return
to_remove = [
ob
for ob in sys.meta_path
if isinstance(ob, importlib_metadata.MetadataPathFinder)
]
for item in to_remove:
sys.meta_path.remove(item)


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

Expand Down

0 comments on commit 4819690

Please sign in to comment.