Commit b596e4b0 authored by Jason R. Coombs's avatar Jason R. Coombs

Replace distutils rather than requiring it to be present in advanec. Instead...

Replace distutils rather than requiring it to be present in advanec. Instead of crashing, issue a warning when Setuptools is replacing distutils.
parent 51e06275
...@@ -11,3 +11,5 @@ used from a setup script as ...@@ -11,3 +11,5 @@ used from a setup script as
import sys import sys
__version__ = sys.version[:sys.version.index(' ')] __version__ = sys.version[:sys.version.index(' ')]
local = True
...@@ -6,8 +6,10 @@ for more motivation. ...@@ -6,8 +6,10 @@ for more motivation.
""" """
import sys import sys
import re
import importlib import importlib
import contextlib import contextlib
import warnings
from os.path import dirname from os.path import dirname
...@@ -21,11 +23,20 @@ def patch_sys_path(): ...@@ -21,11 +23,20 @@ def patch_sys_path():
sys.path[:] = orig 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(): def ensure_local_distutils():
if 'distutils' in sys.modules: clear_distutils()
raise RuntimeError("Distutils must not be imported before setuptools")
with patch_sys_path(): with patch_sys_path():
importlib.import_module('distutils') importlib.import_module('distutils')
assert sys.modules['distutils'].local
ensure_local_distutils() ensure_local_distutils()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment