diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-21 14:47:11 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-21 14:47:11 -0400 |
commit | b596e4b0f684f5ac11673598e1de3aaa5bc74162 (patch) | |
tree | ea5aeae06055c6a4ee3da01be3854ff23d707b65 | |
parent | 51e062754df592b105547abbd6e20851972435d4 (diff) | |
download | external_python_setuptools-b596e4b0f684f5ac11673598e1de3aaa5bc74162.tar.gz external_python_setuptools-b596e4b0f684f5ac11673598e1de3aaa5bc74162.tar.bz2 external_python_setuptools-b596e4b0f684f5ac11673598e1de3aaa5bc74162.zip |
Replace distutils rather than requiring it to be present in advanec. Instead of crashing, issue a warning when Setuptools is replacing distutils.
-rw-r--r-- | distutils/__init__.py | 2 | ||||
-rw-r--r-- | setuptools/distutils_patch.py | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/distutils/__init__.py b/distutils/__init__.py index d823d040..7dac55b6 100644 --- a/distutils/__init__.py +++ b/distutils/__init__.py @@ -11,3 +11,5 @@ used from a setup script as import sys __version__ = sys.version[:sys.version.index(' ')] + +local = True diff --git a/setuptools/distutils_patch.py b/setuptools/distutils_patch.py index 1416a7a3..f9e63798 100644 --- a/setuptools/distutils_patch.py +++ b/setuptools/distutils_patch.py @@ -6,8 +6,10 @@ for more motivation. """ import sys +import re import importlib import contextlib +import warnings from os.path import dirname @@ -21,11 +23,20 @@ def patch_sys_path(): sys.path[:] = orig +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(): - if 'distutils' in sys.modules: - raise RuntimeError("Distutils must not be imported before setuptools") + clear_distutils() with patch_sys_path(): importlib.import_module('distutils') + assert sys.modules['distutils'].local ensure_local_distutils() |