summaryrefslogtreecommitdiff
path: root/_distutils_hack
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-29 10:59:29 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-12-29 10:59:29 -0500
commitda8c68c49646d47b3946e882d402fa32131ade5d (patch)
treebf0133e231a8cf6174a999da44a3e93daef2279d /_distutils_hack
parent41f61f3cce618b594c3c76b78162945f26fa6b61 (diff)
downloadpython-setuptools-git-da8c68c49646d47b3946e882d402fa32131ade5d.tar.gz
Check early for the presence of local distutils and bail out if the found version of Setuptools doesn't have distutils.
Diffstat (limited to '_distutils_hack')
-rw-r--r--_distutils_hack/__init__.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index cb694b34..f64f9fea 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -85,20 +85,18 @@ 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]):
+ try:
+ mod = importlib.import_module('setuptools._distutils')
+ except Exception:
+ # an older Setuptools without a local distutils is taking
+ # precedence, so fall back to stdlib. Ref #2957.
return None
class DistutilsLoader(importlib.abc.Loader):
def create_module(self, spec):
- return importlib.import_module('setuptools._distutils')
+ return mod
def exec_module(self, module):
pass