diff options
-rw-r--r-- | _distutils_hack/__init__.py | 12 | ||||
-rw-r--r-- | changelog.d/2906.misc.rst | 1 |
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. |