diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-07-03 05:18:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-03 05:18:23 -0400 |
commit | 213baae85f0b9c2640fdf7bf270f6b210f119c54 (patch) | |
tree | fb743ec8d5b76f6bec0d3b0660887c03e43e974d /setuptools/distutils_patch.py | |
parent | 78928efa890109410b315b03a225c9fc5f041ff8 (diff) | |
parent | ca0065fb62c1728cb42b86ae79375533856d2248 (diff) | |
download | external_python_setuptools-213baae85f0b9c2640fdf7bf270f6b210f119c54.tar.gz external_python_setuptools-213baae85f0b9c2640fdf7bf270f6b210f119c54.tar.bz2 external_python_setuptools-213baae85f0b9c2640fdf7bf270f6b210f119c54.zip |
Merge pull request #2143 from pypa/distutils
Adopt distutils
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() |