Skip to content

Commit

Permalink
In ensure_local_distutils, re-use DistutilsMetaFinder to load the mod…
Browse files Browse the repository at this point in the history
…ule. Avoids race conditions when _distutils_system_mod is employed and fixes #2906.
  • Loading branch information
jaraco committed Nov 26, 2021
1 parent 4c57dfb commit 485fa84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
1 change: 1 addition & 0 deletions changelog.d/2906.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In ensure_local_distutils, re-use DistutilsMetaFinder to load the module. Avoids race conditions when _distutils_system_mod is employed.

0 comments on commit 485fa84

Please sign in to comment.