diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-03 15:11:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-03 15:11:32 -0400 |
commit | 5f151cbbcd6c65f7f48082bfaf36db3a55df936e (patch) | |
tree | eb721c8957ee48c5149af6742a27a449fb618027 /setuptools/distutils_patch.py | |
parent | a9eb9e73def8ca6c469e59f1b008746e368ad4c1 (diff) | |
parent | a877dab0bddaeb5503d871794ca06f1c81d805b8 (diff) | |
download | external_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.tar.gz external_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.tar.bz2 external_python_setuptools-5f151cbbcd6c65f7f48082bfaf36db3a55df936e.zip |
Merge branch 'master' into 2020-06-11-raise-from
Diffstat (limited to 'setuptools/distutils_patch.py')
-rw-r--r-- | setuptools/distutils_patch.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/setuptools/distutils_patch.py b/setuptools/distutils_patch.py new file mode 100644 index 00000000..b2095fba --- /dev/null +++ b/setuptools/distutils_patch.py @@ -0,0 +1,34 @@ +""" +Ensure that the local copy of distutils is preferred over stdlib. + +See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401 +for more motivation. +""" + +import sys +import re +import importlib +import warnings + + +def clear_distutils(): + if 'distutils' not in sys.modules: + return + warnings.warn("Setuptools is replacing distutils") + mods = [name for name in sys.modules if re.match(r'distutils\b', name)] + for name in mods: + del sys.modules[name] + + +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 + core = importlib.import_module('distutils.core') + assert '_distutils' in core.__file__, core.__file__ + + +ensure_local_distutils() |