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

Update distutils patch to monkeypatch all paths from sys.path to ensure that...

Update distutils patch to monkeypatch all paths from sys.path to ensure that distutils is never imported except from the same path as setuptools. Assert that 'distutils' is not already in sys.modules.
parent b678ce30
......@@ -7,9 +7,23 @@ for more motivation.
import sys
import importlib
import contextlib
from os.path import dirname
sys.path.insert(0, dirname(dirname(__file__)))
importlib.import_module('distutils')
sys.path.pop(0)
@contextlib.contextmanager
def patch_sys_path():
orig = sys.path[:]
sys.path[:] = [dirname(dirname(__file__))]
try:
yield
finally:
sys.path[:] = orig
if 'distutils' in sys.path:
raise RuntimeError("Distutils must not be imported before setuptools")
with patch_sys_path():
importlib.import_module('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