Skip to content

Commit

Permalink
Merge pull request #2962 from nitzmahone/setuptools_picky_shim
Browse files Browse the repository at this point in the history
distutils shim should ignore setuptools on another path
  • Loading branch information
jaraco authored Dec 29, 2021
2 parents e401134 + 6eb6350 commit 104f8b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,23 @@ def spec_for_distutils(self):
import importlib.abc
import importlib.util

# In cases of path manipulation during sitecustomize,
# Setuptools might actually not be present even though
# the hook has been loaded. Allow the caller to fall
# back to stdlib behavior. See #2980.
if not importlib.util.find_spec('setuptools'):
try:
mod = importlib.import_module('setuptools._distutils')
except Exception:
# There are a couple of cases where setuptools._distutils
# may not be present:
# - An older Setuptools without a local distutils is
# taking precedence. Ref #2957.
# - Path manipulation during sitecustomize removes
# setuptools from the path but only after the hook
# has been loaded. Ref #2980.
# In either case, fall back to stdlib behavior.
return

class DistutilsLoader(importlib.abc.Loader):

def create_module(self, spec):
return importlib.import_module('setuptools._distutils')
return mod

def exec_module(self, module):
pass
Expand Down
1 change: 1 addition & 0 deletions changelog.d/2962.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid attempting to use local distutils when the presiding version of Setuptools on the path doesn't have one.

0 comments on commit 104f8b4

Please sign in to comment.