aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-03-20 12:59:14 -0700
committerJason R. Coombs <jaraco@jaraco.com>2013-03-20 12:59:14 -0700
commit32c396c0bbc2e1ff07bf5bc8f0183c38234de246 (patch)
tree148c2e461c6035a4a17016ff7f59d4fc36ea9e33 /setuptools
parentd54b82ff21706452e66ae1b7f59fb6d5945fab4d (diff)
parent6b9f1df35359a8a7b43975b32ee79d8f7259d8c8 (diff)
downloadexternal_python_setuptools-32c396c0bbc2e1ff07bf5bc8f0183c38234de246.tar.gz
external_python_setuptools-32c396c0bbc2e1ff07bf5bc8f0183c38234de246.tar.bz2
external_python_setuptools-32c396c0bbc2e1ff07bf5bc8f0183c38234de246.zip
Merged sandbox module
--HG-- branch : Setuptools-Distribute merge
Diffstat (limited to 'setuptools')
-rwxr-xr-xsetuptools/sandbox.py47
1 files changed, 38 insertions, 9 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py
index 1583b81f..e026ff13 100755
--- a/setuptools/sandbox.py
+++ b/setuptools/sandbox.py
@@ -9,9 +9,40 @@ except NameError:
_file = None
_open = open
from distutils.errors import DistutilsError
+from pkg_resources import working_set
+
__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()
@@ -29,6 +60,9 @@ def run_setup(setup_script, args):
try:
sys.argv[:] = [setup_script]+list(args)
sys.path.insert(0, setup_dir)
+ # reset to include setup dir, w/clean callback list
+ working_set.__init__()
+ working_set.callbacks.append(lambda dist:dist.activate())
DirectorySandbox(setup_dir).run(
lambda: execfile(
"setup.py",
@@ -55,6 +89,8 @@ def run_setup(setup_script, args):
sys.argv[:] = save_argv
tempfile.tempdir = save_tmp
+
+
class AbstractSandbox:
"""Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""
@@ -86,7 +122,6 @@ class AbstractSandbox:
__builtin__.open = _open
self._copy(_os)
-
def _mk_dual_path_wrapper(name):
original = getattr(_os,name)
def wrap(self,src,dst,*args,**kw):
@@ -95,7 +130,6 @@ class AbstractSandbox:
return original(src,dst,*args,**kw)
return wrap
-
for name in ["rename", "link", "symlink"]:
if hasattr(_os,name): locals()[name] = _mk_dual_path_wrapper(name)
@@ -118,7 +152,6 @@ class AbstractSandbox:
]:
if hasattr(_os,name): locals()[name] = _mk_single_path_wrapper(name)
-
def _mk_single_with_return(name):
original = getattr(_os,name)
def wrap(self,path,*args,**kw):
@@ -208,6 +241,7 @@ class DirectorySandbox(AbstractSandbox):
self._violation("tmpnam")
def _ok(self,path):
+ if hasattr(_os,'devnull') and path==_os.devnull: return True
active = self._active
try:
self._active = False
@@ -240,16 +274,11 @@ class DirectorySandbox(AbstractSandbox):
self._violation("os.open", file, flags, mode)
return _os.open(file,flags,mode)
-
WRITE_FLAGS = reduce(
- operator.or_,
- [getattr(_os, a, 0) for a in
+ operator.or_, [getattr(_os, a, 0) for a in
"O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY".split()]
)
-
-
-
class SandboxViolation(DistutilsError):
"""A setup script attempted to modify the filesystem outside the sandbox"""