Skip to content

Commit

Permalink
Suppress distutils replacement when building or testing CPython. Fixes
Browse files Browse the repository at this point in the history
…#2965. Fixes #3007.
  • Loading branch information
jaraco committed Jan 16, 2022
1 parent ecfcf07 commit 999358b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
24 changes: 16 additions & 8 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def find_spec(self, fullname, path, target=None):
return method()

def spec_for_distutils(self):
if self.is_cpython():
return

import importlib
import importlib.abc
import importlib.util
Expand Down Expand Up @@ -118,6 +121,14 @@ def exec_module(self, module):
'distutils', DistutilsLoader(), origin=mod.__file__
)

@staticmethod
def is_cpython():
"""
Suppress supplying distutils for CPython (build and tests).
Ref #2965 and #3007.
"""
return os.path.isfile('pybuilddir.txt')

def spec_for_pip(self):
"""
Ensure stdlib distutils when running under pip.
Expand All @@ -135,9 +146,9 @@ def spec_for_setuptools(self):
a stubbed spec to represent setuptools being present
without invoking any behavior.
Workaround for pypa/get-pip#137.
Workaround for pypa/get-pip#137. Ref #2993.
"""
if not self.is_get_pip():
if not self.is_script('get-pip'):
return

import importlib
Expand Down Expand Up @@ -166,14 +177,11 @@ def pip_imported_during_build(cls):
for frame, line in traceback.walk_stack(None)
)

@classmethod
def is_get_pip(cls):
"""
Detect if get-pip is being invoked. Ref #2993.
"""
@staticmethod
def is_script(name):
try:
import __main__
return os.path.basename(__main__.__file__) == 'get-pip.py'
return os.path.basename(__main__.__file__) == f'{name}.py'
except AttributeError:
pass

Expand Down
1 change: 1 addition & 0 deletions changelog.d/3031.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress distutils replacement when building or testing CPython.
Empty file added changelog.d/NNN.misc.rst
Empty file.

0 comments on commit 999358b

Please sign in to comment.