Commit 30039129 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Use a dedicated buildout directory for building a rebootstrap python.

parent 4c8cca26
...@@ -24,13 +24,18 @@ class Rebootstrap: ...@@ -24,13 +24,18 @@ class Rebootstrap:
def __init__(self, buildout): def __init__(self, buildout):
self.logger = logging.getLogger(__name__) self.logger = logging.getLogger(__name__)
self.buildout = buildout self.buildout = buildout
buildout_directory = buildout['buildout']['directory']
self.rebootstrap_directory = os.path.join(
buildout_directory, 'rebootstrap'
)
# fetch section to build python, obligatory # fetch section to build python, obligatory
self.python_section = ( self.python_section = (
buildout['buildout'].get('python') or \ buildout['buildout'].get('python') or \
buildout['rebootstrap']['section'] buildout['rebootstrap']['section']
).strip() ).strip()
self.wanted_python = buildout[self.python_section]['executable'] self.wanted_python = buildout[self.python_section]['executable'].replace(
buildout_directory, self.rebootstrap_directory
)
# query for currently running python # query for currently running python
self.running_python = sys.executable self.running_python = sys.executable
...@@ -53,12 +58,12 @@ Buildout will be restarted automatically to have this change applied. ...@@ -53,12 +58,12 @@ Buildout will be restarted automatically to have this change applied.
self.logger.info(message) self.logger.info(message)
args = map(zc.buildout.easy_install._safe_arg, sys.argv) args = map(zc.buildout.easy_install._safe_arg, sys.argv)
env = os.environ env = os.environ
env['ORIG_PYTHON'] = sys.executable
os.execve(self.wanted_python, [self.wanted_python] + args, env) os.execve(self.wanted_python, [self.wanted_python] + args, env)
def install_section(self): def install_section(self):
env = os.environ # For safety, we always try to install/update instead of the condition
if not os.path.exists(self.wanted_python): # if not os.path.exists(self.wanted_python):
if True:
self.logger.info('Installing section %r to provide %r' % ( self.logger.info('Installing section %r to provide %r' % (
self.python_section, self.wanted_python)) self.python_section, self.wanted_python))
args = map(zc.buildout.easy_install._safe_arg, sys.argv) args = map(zc.buildout.easy_install._safe_arg, sys.argv)
...@@ -72,6 +77,8 @@ Buildout will be restarted automatically to have this change applied. ...@@ -72,6 +77,8 @@ Buildout will be restarted automatically to have this change applied.
# rerun buildout with only neeeded section to reuse buildout # rerun buildout with only neeeded section to reuse buildout
# ability to calcuate all dependency # ability to calcuate all dependency
args.extend([ args.extend([
# chroot to rebootstrap directory
'buildout:directory=%s' % self.rebootstrap_directory,
# install only required section with dependencies # install only required section with dependencies
'buildout:parts=%s' % self.python_section, 'buildout:parts=%s' % self.python_section,
# do not load this extension # do not load this extension
...@@ -89,26 +96,3 @@ Buildout will be restarted automatically to have this change applied. ...@@ -89,26 +96,3 @@ Buildout will be restarted automatically to have this change applied.
'%r\nUnfortunately even after installing this section executable was' '%r\nUnfortunately even after installing this section executable was'
' not found.\nThis is section responsibility to provide python (eg. ' ' not found.\nThis is section responsibility to provide python (eg. '
'by compiling it).' % (self.python_section, self.wanted_python)) 'by compiling it).' % (self.python_section, self.wanted_python))
_uninstall_part_orig = zc.buildout.buildout.Buildout._uninstall_part
def _uninstall_part(self, part, installed_part_options):
_uninstall_part_orig(self, part, installed_part_options)
try:
location = self[part].get('location')
except zc.buildout.buildout.MissingSection:
return
if location and sys.executable.startswith(location):
message = """
************ REBOOTSTRAP: IMPORTANT NOTICE ************
%r part that provides the running Python is uninstalled.
Buildout will be restarted automatically with the original Python.
************ REBOOTSTRAP: IMPORTANT NOTICE ************
""" % part
self._logger.info(message)
if getattr(self, 'dry_run', False):
sys.exit()
args = map(zc.buildout.easy_install._safe_arg, sys.argv)
env = os.environ
orig_python = env['ORIG_PYTHON']
os.execve(orig_python, [orig_python] + args, env)
zc.buildout.buildout.Buildout._uninstall_part = _uninstall_part
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