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