summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-11-26 11:11:43 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-11-26 12:50:02 -0500
commit485fa84d85da3ab6892a9e591b111fbb094c1c9a (patch)
treeb025bed3e72ecc3174ea2eb5858458622be94909
parent4c57dfb7b4d4a6765a1aa4d0ef7edf14e8284fe9 (diff)
downloadpython-setuptools-git-bugfix/2906-distutils-race.tar.gz
In ensure_local_distutils, re-use DistutilsMetaFinder to load the module. Avoids race conditions when _distutils_system_mod is employed and fixes #2906.bugfix/2906-distutils-race
-rw-r--r--_distutils_hack/__init__.py12
-rw-r--r--changelog.d/2906.misc.rst1
2 files changed, 9 insertions, 4 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index 5f40996a..bcac4111 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -48,11 +48,15 @@ def enabled():
def ensure_local_distutils():
clear_distutils()
- distutils = importlib.import_module('setuptools._distutils')
- distutils.__name__ = 'distutils'
- sys.modules['distutils'] = distutils
- # sanity check that submodules load as expected
+ # ensure the DistutilsMetaFinder is in place and
+ # perform an import to cause distutils to be
+ # loaded from setuptools._distutils. Ref #2906.
+ add_shim()
+ importlib.import_module('distutils')
+ remove_shim()
+
+ # check that submodules load as expected
core = importlib.import_module('distutils.core')
assert '_distutils' in core.__file__, core.__file__
diff --git a/changelog.d/2906.misc.rst b/changelog.d/2906.misc.rst
new file mode 100644
index 00000000..2ec890b4
--- /dev/null
+++ b/changelog.d/2906.misc.rst
@@ -0,0 +1 @@
+In ensure_local_distutils, re-use DistutilsMetaFinder to load the module. Avoids race conditions when _distutils_system_mod is employed.