resurrect preferred=True option for packages lost in merge of externals support.

- Pyton 2.7.11 is preferred again.
This commit is contained in:
Todd Gamblin 2016-03-23 01:32:54 -07:00
parent c4134ee71e
commit 38350ae33d
3 changed files with 14 additions and 3 deletions

View file

@ -159,6 +159,10 @@ def concretize_version(self, spec):
if any(v.satisfies(sv) for sv in spec.versions)], if any(v.satisfies(sv) for sv in spec.versions)],
cmp=cmp_versions) cmp=cmp_versions)
def prefer_key(v):
return pkg.versions.get(Version(v)).get('preferred', False)
valid_versions.sort(key=prefer_key, reverse=True)
if valid_versions: if valid_versions:
spec.versions = ver([valid_versions[0]]) spec.versions = ver([valid_versions[0]])
else: else:

View file

@ -150,9 +150,7 @@ def spec_has_preferred_provider(self, pkgname, provider_str):
def version_compare(self, pkgname, a, b): def version_compare(self, pkgname, a, b):
"""Return less-than-0, 0, or greater than 0 if version a of pkgname is """Return less-than-0, 0, or greater than 0 if version a of pkgname is
respecively less-than, equal-to, or greater-than version b of pkgname. respecively less-than, equal-to, or greater-than version b of pkgname.
Versions marked 'preferred=True' in package.py take precedence over any One version is less-than another if it is preferred over the other."""
versions not marked preferred.
"""
return self._spec_compare(pkgname, 'version', a, b, True, None) return self._spec_compare(pkgname, 'version', a, b, True, None)

View file

@ -24,6 +24,7 @@
############################################################################## ##############################################################################
import spack import spack
from spack.spec import Spec, CompilerSpec from spack.spec import Spec, CompilerSpec
from spack.version import ver
from spack.concretize import find_spec from spack.concretize import find_spec
from spack.test.mock_packages_test import * from spack.test.mock_packages_test import *
@ -77,6 +78,14 @@ def test_concretize_variant(self):
self.check_concretize('mpich') self.check_concretize('mpich')
def test_concretize_preferred_version(self):
spec = self.check_concretize('python')
self.assertEqual(spec.versions, ver('2.7.11'))
spec = self.check_concretize('python@3.5.1')
self.assertEqual(spec.versions, ver('3.5.1'))
def test_concretize_with_virtual(self): def test_concretize_with_virtual(self):
self.check_concretize('mpileaks ^mpi') self.check_concretize('mpileaks ^mpi')
self.check_concretize('mpileaks ^mpi@:1.1') self.check_concretize('mpileaks ^mpi@:1.1')