class UnpickleableException(Exception): """
An exception representing another Exception that could not be pickled. """
@staticmethod def dump(type, exc): """
Always return a dumped (pickled) type and exc. If exc can't be pickled,
wrap it in UnpickleableException first. """ try: return pickle.dumps(type), pickle.dumps(exc) except Exception: # get UnpickleableException inside the sandbox from setuptools.sandbox import UnpickleableException as cls
return cls.dump(cls, cls(repr(exc)))
class ExceptionSaver: """
A Context Manager that will save an exception, serialize, and restore it
later. """
@contextlib.contextmanager def save_modules(): """
Context in which imported modules are saved.
Translates exceptions internal to the context into the equivalent exception
outside the context. """
saved = sys.modules.copy() with ExceptionSaver() as saved_exc: yield saved
sys.modules.update(saved) # remove any modules imported since
del_modules = (
mod_name for mod_name in sys.modules if mod_name notin saved # exclude any encodings modules. See #285 andnot mod_name.startswith('encodings.')
)
_clear_modules(del_modules)
saved_exc.resume()
def _clear_modules(module_names): for mod_name in list(module_names): del sys.modules[mod_name]
@contextlib.contextmanager def setup_context(setup_dir):
temp_dir = os.path.join(setup_dir, 'temp') with save_pkg_resources_state(): with save_modules(): with save_path():
hide_setuptools() with save_argv(): with override_temp(temp_dir): with pushd(setup_dir): # ensure setuptools commands are available
__import__('setuptools') yield
def hide_setuptools(): """
Remove references to setuptools' modules from sys.modules to allow the
invocation to import the most appropriate setuptools. This technique is
necessary to avoid issues such as#315 where setuptools upgrading itself
would fail to find a function declared in the metadata. """
_distutils_hack = sys.modules.get('_distutils_hack', None) if _distutils_hack isnotNone:
_distutils_hack._remove_shim()
def run_setup(setup_script, args): """Run a distutils setup script, sandboxed in its directory"""
setup_dir = os.path.abspath(os.path.dirname(setup_script)) with setup_context(setup_dir): 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())
with DirectorySandbox(setup_dir):
ns = dict(__file__=setup_script, __name__='__main__')
_execfile(setup_script, ns) except SystemExit as v: if v.args and v.args[0]: raise # Normal exit, just return
class AbstractSandbox: """Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""
_active = False
def __init__(self):
self._attrs = [
name for name in dir(_os) ifnot name.startswith('_') and hasattr(self, name)
]
def _copy(self, source): for name in self._attrs:
setattr(os, name, getattr(source, name))
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available. """
).lstrip()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.