[Python-checkins] r65949 - sandbox/trunk/setuptools/setuptools/sandbox.py
phillip.eby
python-checkins at python.org
Thu Aug 21 20:42:07 CEST 2008
Author: phillip.eby
Date: Thu Aug 21 20:41:59 2008
New Revision: 65949
Log:
Candidate fix for http://bugs.python.org/setuptools/issue20
Modified:
sandbox/trunk/setuptools/setuptools/sandbox.py
Modified: sandbox/trunk/setuptools/setuptools/sandbox.py
==============================================================================
--- sandbox/trunk/setuptools/setuptools/sandbox.py (original)
+++ sandbox/trunk/setuptools/setuptools/sandbox.py Thu Aug 21 20:41:59 2008
@@ -5,10 +5,8 @@
__all__ = [
"AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup",
]
-
def run_setup(setup_script, args):
"""Run a distutils setup script, sandboxed in its directory"""
-
old_dir = os.getcwd()
save_argv = sys.argv[:]
save_path = sys.path[:]
@@ -16,10 +14,9 @@
temp_dir = os.path.join(setup_dir,'temp')
if not os.path.isdir(temp_dir): os.makedirs(temp_dir)
save_tmp = tempfile.tempdir
-
+ save_modules = sys.modules.copy()
try:
- tempfile.tempdir = temp_dir
- os.chdir(setup_dir)
+ tempfile.tempdir = temp_dir; os.chdir(setup_dir)
try:
sys.argv[:] = [setup_script]+list(args)
sys.path.insert(0, setup_dir)
@@ -34,6 +31,9 @@
raise
# Normal exit, just return
finally:
+ sys.modules.update(save_modules)
+ for key in list(sys.modules):
+ if key not in save_modules: del sys.modules[key]
os.chdir(old_dir)
sys.path[:] = save_path
sys.argv[:] = save_argv
More information about the Python-checkins
mailing list