Commit e3ee34e8 authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: buildout script not sorted

Solution: sort accordingly
parent 86818e5b
......@@ -608,9 +608,16 @@ class Buildout(DictMixin):
ws = pkg_resources.WorkingSet(entries)
ws.require('zc.buildout')
options = self['buildout']
eggs_dir = options['eggs-directory']
develop_eggs_dir = options['develop-eggs-directory']
ws = zc.buildout.easy_install.sort_working_set(
ws,
eggs_dir=eggs_dir,
develop_eggs_dir=develop_eggs_dir
)
zc.buildout.easy_install.scripts(
['zc.buildout'], ws, sys.executable,
self['buildout']['bin-directory'],
options['bin-directory'],
relative_paths = (
bool_option(options, 'relative-paths', False)
and options['directory']
......@@ -1147,9 +1154,16 @@ class Buildout(DictMixin):
# the new dist is different, so we've upgraded.
# Update the scripts and return True
options = self['buildout']
eggs_dir = options['eggs-directory']
develop_eggs_dir = options['develop-eggs-directory']
ws = zc.buildout.easy_install.sort_working_set(
ws,
eggs_dir=eggs_dir,
develop_eggs_dir=develop_eggs_dir
)
zc.buildout.easy_install.scripts(
['zc.buildout'], ws, sys.executable,
self['buildout']['bin-directory'],
options['bin-directory'],
relative_paths = (
bool_option(options, 'relative-paths', False)
and options['directory']
......
......@@ -1141,19 +1141,14 @@ def scripts(reqs, working_set, executable, dest=None,
):
assert executable == sys.executable, (executable, sys.executable)
# ensure eggs are inserted before ``site-packages`` in ``sys.path``.
# TODO ensure develop-eggs are also inserted before ``site-packages``.
dists = [dist for dist in working_set]
dists.sort(key=lambda dist: (-dist.precedence, dist.project_name))
path = [dist.location for dist in dists]
path = [dist.location for dist in working_set]
path.extend(extra_paths)
# order preserving unique
unique_path = []
for p in path:
if p not in unique_path:
unique_path.append(p)
path = list(map(realpath, unique_path))
path = [realpath(p) for p in unique_path]
generated = []
......@@ -1929,3 +1924,28 @@ def _move_to_eggs_dir_and_compile(dist, dest):
if installed_with_pip:
newdist.precedence = pkg_resources.EGG_DIST
return newdist
def sort_working_set(ws, eggs_dir, develop_eggs_dir):
develop_paths = set()
pattern = os.path.join(develop_eggs_dir, '*.egg-link')
for egg_link in glob.glob(pattern):
with open(egg_link, 'rt') as f:
path = f.readline().strip()
if path:
develop_paths.add(path)
sorted_paths = []
egg_paths = []
other_paths = []
for dist in ws:
path = dist.location
if path in develop_paths:
sorted_paths.append(path)
elif os.path.commonprefix([path, eggs_dir]) == eggs_dir:
egg_paths.append(path)
else:
other_paths.append(path)
sorted_paths.extend(egg_paths)
sorted_paths.extend(other_paths)
return pkg_resources.WorkingSet(sorted_paths)
......@@ -920,8 +920,8 @@ to pass a common base directory of the scripts and eggs:
<BLANKLINE>
import sys
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
join(base, 'eggs/demo-0.3-pyN.N.egg'),
'/ba',
join(base, 'bar'),
base,
......@@ -954,8 +954,8 @@ We specified an interpreter and its paths are adjusted too:
import sys
<BLANKLINE>
sys.path[0:0] = [
join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
join(base, 'eggs/demo-0.3-pyN.N.egg'),
'/ba',
join(base, 'bar'),
base,
......
......@@ -95,31 +95,6 @@ class Eggs(object):
update = install
def _sort_working_set(self, ws):
develop_paths = set()
pattern = os.path.join(self.options['develop-eggs-directory'], '*.egg-link')
for egg_link in glob.glob(pattern):
with open(egg_link, 'rt') as f:
path = f.readline().strip()
if path:
develop_paths.add(path)
egg_directory = os.path.join(self.options['eggs-directory'], '')
sorted_paths = []
egg_paths = []
other_paths = []
for dist in ws:
path = dist.location
if path in develop_paths:
sorted_paths.append(path)
elif os.path.commonprefix([path, egg_directory]) == egg_directory:
egg_paths.append(path)
else:
other_paths.append(path)
sorted_paths.extend(egg_paths)
sorted_paths.extend(other_paths)
return pkg_resources.WorkingSet(sorted_paths)
def _working_set(
self,
distributions,
......@@ -166,7 +141,9 @@ class Eggs(object):
newest=newest,
allow_hosts=allow_hosts,
allow_unknown_extras=allow_unknown_extras)
ws = self._sort_working_set(ws)
ws = zc.buildout.easy_install.sort_working_set(
ws, eggs_dir, develop_eggs_dir
)
cache_storage[cache_key] = ws
# `pkg_resources.WorkingSet` instances are mutable, so we need to return
......
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