Commit 785b425d authored by Xavier Thompson's avatar Xavier Thompson

Unify rebootstrap mechanisms

Drop special-case hack when the initial and the target Python have
the same version. This used the initial Python to generate the
bin/buildout for the target Python. This could cause issues because
the initial and the target Python are unlikely to share the same
sites-packages, and this influences script generation.

The new rebootstrap mechanism also works when the Python versions
are the same, so it can be used in all cases.

Removing this hack also reduces even more the dependency on private
internal APIs of zc.buildout.
parent ab044127
......@@ -12,9 +12,9 @@
#
##############################################################################
import errno, logging, os, shutil, subprocess, sys, tempfile
import errno, logging, os, shutil, subprocess, sys
import pkg_resources
from zc.buildout import easy_install, UserError
from zc.buildout import UserError
buildout_dist = pkg_resources.get_distribution('zc.buildout')
......@@ -25,16 +25,7 @@ if 'slapos' not in str(buildout_dist.version):
% buildout_dist)
class FakeSysExecutable(object):
def __init__(self, python):
self.executable = python
def __getattr__(self, attr):
return getattr(sys, attr)
def get_distributions():
def get_paths():
# zc.buildout and dependencies
dists = pkg_resources.require('zc.buildout')
# propagate slapos.libnetworkcache availability
......@@ -44,36 +35,8 @@ def get_distributions():
except ImportError:
pass
# keep same order as in sys.path
dists.sort(key=lambda d: sys.path.index(d.location))
return dists
def get_paths():
path = None
paths = []
# order preserving unique, knowing that duplicates can only be adjacent
for dist in get_distributions():
if path != dist.location:
path = dist.location
paths.append(path)
return paths
def setup_script(path, python=sys.executable):
from zc.buildout import easy_install
executable_path = os.path.realpath(path)
assert os.path.isabs(executable_path)
try:
if sys.executable != python:
easy_install.sys = FakeSysExecutable(python)
easy_install.scripts(
((os.path.basename(executable_path), 'zc.buildout.buildout', 'main'),),
get_distributions(),
python,
os.path.dirname(executable_path)
)
finally:
easy_install.sys = sys
paths = {d.location for d in dists}
return [p for p in sys.path if p in paths]
class extension(object):
......@@ -132,25 +95,19 @@ Buildout will be restarted automatically to have this change applied.
if x == '#!' + self.wanted_python:
shutil.copy(new_bin, installed)
else:
if subprocess.call((self.wanted_python, '-c',
'import sys; sys.exit(sys.version_info[:2] == %r)'
% (sys.version_info[:2],))):
setup_script(new_bin, self.wanted_python)
shutil.copy(new_bin, installed)
else:
old = installed + '-old'
shutil.move(installed, old)
try:
paths = get_paths()
args = [arg for arg in sys.argv if arg.startswith('buildout:')]
subprocess.check_call(
[self.wanted_python, '-c',
"import sys ; sys.path[0:0]=%r ; "
"import zc.buildout.buildout ; "
"sys.argv[1:1]=%r ; "
"zc.buildout.buildout.main()" % (paths, args + ['bootstrap'])])
except subprocess.CalledProcessError:
shutil.move(old, installed)
raise
shutil.copy(installed, new_bin)
old = installed + '-old'
shutil.move(installed, old)
try:
paths = get_paths()
args = [arg for arg in sys.argv if arg.startswith('buildout:')]
subprocess.check_call(
[self.wanted_python, '-c',
"import sys ; sys.path[0:0]=%r ; "
"import zc.buildout.buildout ; "
"sys.argv[1:1]=%r ; "
"zc.buildout.buildout.main()" % (paths, args + ['bootstrap'])])
except subprocess.CalledProcessError:
shutil.move(old, installed)
raise
shutil.copy(installed, new_bin)
os.execve(self.wanted_python, [self.wanted_python] + sys.argv, self.environ)
......@@ -35,7 +35,7 @@ is available, and buildout is using another python:
Buildout will be restarted automatically to have this change applied.
************ REBOOTSTRAP: IMPORTANT NOTICE ************
<BLANKLINE>
Generated script '/sample-buildout/bin/buildout-rebootstrap'.
Generated script '/sample-buildout/bin/buildout'.
Develop: '/sample-buildout/recipes'
Updating installpython.
Installing realrun.
......
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