aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-05-25 13:38:15 -0400
committerJason R. Coombs <jaraco@jaraco.com>2020-05-25 16:16:35 -0400
commit151599602b9d626ebcfe5ae6960ea216b767fec2 (patch)
tree5f89e00d9f334fd6ff343164c52bb8cf01dbc805 /setuptools
parentb678ce30a356abb36cd49d523731a9f978fce0bf (diff)
downloadexternal_python_setuptools-151599602b9d626ebcfe5ae6960ea216b767fec2.tar.gz
external_python_setuptools-151599602b9d626ebcfe5ae6960ea216b767fec2.tar.bz2
external_python_setuptools-151599602b9d626ebcfe5ae6960ea216b767fec2.zip
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.
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/distutils_patch.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/setuptools/distutils_patch.py b/setuptools/distutils_patch.py
index a2fc1a8c..e0abbd77 100644
--- a/setuptools/distutils_patch.py
+++ b/setuptools/distutils_patch.py
@@ -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')