summaryrefslogtreecommitdiff
path: root/_distutils_hack
diff options
context:
space:
mode:
authorMatt Davis <mrd@redhat.com>2021-12-23 11:45:22 -0800
committerMatt Davis <mrd@redhat.com>2021-12-23 11:45:22 -0800
commit15340a3f1ec40e4d7267518d04487d7b4108ee83 (patch)
tree755401902e02a81d04b69723142a751814f460b5 /_distutils_hack
parent52c990172fec37766b3566679724aa8bf70ae06d (diff)
downloadpython-setuptools-git-15340a3f1ec40e4d7267518d04487d7b4108ee83.tar.gz
distutils shim should ignore setuptools on another path
Diffstat (limited to '_distutils_hack')
-rw-r--r--_distutils_hack/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index 22bc9ed6..a5c8e1cf 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -58,7 +58,9 @@ def ensure_local_distutils():
# check that submodules load as expected
core = importlib.import_module('distutils.core')
- assert '_distutils' in core.__file__, core.__file__
+ # FIXME: this assertion blows up if the MetaFinder below has no-opped on a
+ # setuptools from another path
+ # assert '_distutils' in core.__file__, core.__file__
def do_override():
@@ -85,6 +87,15 @@ class DistutilsMetaFinder:
def spec_for_distutils(self):
import importlib.abc
import importlib.util
+ from pathlib import Path
+
+ st_mod = importlib.import_module('setuptools')
+
+ # prevent this import redirection shim from interacting with a possibly
+ # incompatible setuptools in another location on sys.path
+ # see pypa/setuptools#2957
+ if not Path(__file__).parents[1].samefile(Path(st_mod.__file__).parents[1]):
+ return None
class DistutilsLoader(importlib.abc.Loader):