Skip to content

Commit 485fa84

Browse files
committed
In ensure_local_distutils, re-use DistutilsMetaFinder to load the module. Avoids race conditions when _distutils_system_mod is employed and fixes #2906.
1 parent 4c57dfb commit 485fa84

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

_distutils_hack/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ def enabled():
4848

4949
def ensure_local_distutils():
5050
clear_distutils()
51-
distutils = importlib.import_module('setuptools._distutils')
52-
distutils.__name__ = 'distutils'
53-
sys.modules['distutils'] = distutils
5451

55-
# sanity check that submodules load as expected
52+
# ensure the DistutilsMetaFinder is in place and
53+
# perform an import to cause distutils to be
54+
# loaded from setuptools._distutils. Ref #2906.
55+
add_shim()
56+
importlib.import_module('distutils')
57+
remove_shim()
58+
59+
# check that submodules load as expected
5660
core = importlib.import_module('distutils.core')
5761
assert '_distutils' in core.__file__, core.__file__
5862

changelog.d/2906.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In ensure_local_distutils, re-use DistutilsMetaFinder to load the module. Avoids race conditions when _distutils_system_mod is employed.

0 commit comments

Comments
 (0)