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