From da8c68c49646d47b3946e882d402fa32131ade5d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 29 Dec 2021 10:59:29 -0500 Subject: Check early for the presence of local distutils and bail out if the found version of Setuptools doesn't have distutils. --- _distutils_hack/__init__.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to '_distutils_hack') 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 -- cgit v1.2.1