Commit fa3779fa authored by tarek's avatar tarek

avoid sandbox violations on installation fixes #100

--HG--
branch : distribute
extra : rebase_source : 30a4c67f59ad25edf59133af2986191265811635
parent ce6ac29b
......@@ -26,6 +26,8 @@ CHANGES
anymore under py3 with C or POSIX local. Contributed by Arfrever.
* Issue 104: remvoved the assertion when the installation fails,
with a nicer message for the end user.
* Issue 100: making sure there's no SandboxViolation when
the setup script patches setuptools.
-----
0.6.8
......
......@@ -224,22 +224,34 @@ def _patch_file(path, content):
def _same_content(path, content):
return open(path).read() == content
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
def _no_sandbox(function):
def __no_sandbox(*args, **kw):
try:
from setuptools.sandbox import DirectorySandbox
def _violation(*args):
def violation(*args):
pass
DirectorySandbox._violation = _violation
DirectorySandbox._old = DirectorySandbox._violation
DirectorySandbox._violation = violation
patched = True
except ImportError:
pass
patched = False
try:
return function(*args, **kw)
finally:
if patched:
DirectorySandbox._violation = DirectorySandbox._old
del DirectorySandbox._old
return __no_sandbox
@_no_sandbox
def _rename_path(path):
new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name)
return new_name
def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder)
......@@ -279,6 +291,7 @@ def _after_install(dist):
placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder)
@_no_sandbox
def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location')
......@@ -290,12 +303,14 @@ def _create_fake_setuptools_pkg_info(placeholder):
if os.path.exists(pkg_info):
log.warn('%s already exists', pkg_info)
return
log.warn('Creating %s', pkg_info)
f = open(pkg_info, 'w')
try:
f.write(SETUPTOOLS_PKG_INFO)
finally:
f.close()
pth_file = os.path.join(placeholder, 'setuptools.pth')
log.warn('Creating %s', pth_file)
f = open(pth_file, 'w')
......@@ -304,7 +319,6 @@ def _create_fake_setuptools_pkg_info(placeholder):
finally:
f.close()
def _patch_egg_dir(path):
# let's check if it's already patched
pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
......
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