aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/sandbox.py
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2020-07-13 14:43:23 -0400
committerPaul Ganssle <paul@ganssle.io>2020-07-13 15:42:24 -0400
commit89e9d3c8910c3f419eb9f1c2758a748c6938655b (patch)
tree38956efee3d75858b2d53e4db5cd61e5d8e0d773 /setuptools/sandbox.py
parent03b36b5dc594bbe239d0ad66dc43ea7d1832072c (diff)
downloadexternal_python_setuptools-89e9d3c8910c3f419eb9f1c2758a748c6938655b.tar.gz
external_python_setuptools-89e9d3c8910c3f419eb9f1c2758a748c6938655b.tar.bz2
external_python_setuptools-89e9d3c8910c3f419eb9f1c2758a748c6938655b.zip
Adjust distutils shim when removing _distutils_importer
Diffstat (limited to 'setuptools/sandbox.py')
-rw-r--r--setuptools/sandbox.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index 93ae8eb4..342a713f 100644
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -185,8 +185,8 @@ def setup_context(setup_dir):
temp_dir = os.path.join(setup_dir, 'temp')
with save_pkg_resources_state():
with save_modules():
- hide_setuptools()
with save_path():
+ hide_setuptools()
with save_argv():
with override_temp(temp_dir):
with pushd(setup_dir):
@@ -195,6 +195,15 @@ def setup_context(setup_dir):
yield
+_MODULES_TO_HIDE = {
+ 'setuptools',
+ 'distutils',
+ 'pkg_resources',
+ 'Cython',
+ '_distutils_importer',
+}
+
+
def _needs_hiding(mod_name):
"""
>>> _needs_hiding('setuptools')
@@ -212,8 +221,8 @@ def _needs_hiding(mod_name):
>>> _needs_hiding('Cython')
True
"""
- pattern = re.compile(r'(setuptools|pkg_resources|distutils|Cython)(\.|$)')
- return bool(pattern.match(mod_name))
+ base_module = mod_name.split('.', 1)[0]
+ return base_module in _MODULES_TO_HIDE
def hide_setuptools():
@@ -223,6 +232,10 @@ def hide_setuptools():
necessary to avoid issues such as #315 where setuptools upgrading itself
would fail to find a function declared in the metadata.
"""
+ _distutils_importer = sys.modules.get('_distutils_importer', None)
+ if _distutils_importer is not None:
+ _distutils_importer.remove_shim()
+
modules = filter(_needs_hiding, sys.modules)
_clear_modules(modules)