diff options
author | scheibelp <scheibel1@llnl.gov> | 2017-07-31 13:11:08 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2017-07-31 13:11:08 -0700 |
commit | 69a6c8ef7880a12cf3300af45317fac94b374df1 (patch) | |
tree | cbf4a28a80d906bed910dad1c7fe29f0622b5ff2 /lib | |
parent | 1c7e5724d9ff90b27f31faffd712867520e400c6 (diff) | |
download | spack-69a6c8ef7880a12cf3300af45317fac94b374df1.tar.gz spack-69a6c8ef7880a12cf3300af45317fac94b374df1.tar.bz2 spack-69a6c8ef7880a12cf3300af45317fac94b374df1.tar.xz spack-69a6c8ef7880a12cf3300af45317fac94b374df1.zip |
Fix preference for X.Y version when mixed with X.Y.Z versions (#4922)
For packages which contain a mix of versions with formats X.Y and
X.Y.Z, if the user entered an X.Y version as a preference in
packages.yaml, Spack would get confused and favor any version A.B.Z
where X=A and Y=B. In the case where there is a mix of these version
types, this commit updates preferences so Spack will favor an exact
match.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/package_prefs.py | 10 | ||||
-rw-r--r-- | lib/spack/spack/test/concretize_preferences.py | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/spack/spack/package_prefs.py b/lib/spack/spack/package_prefs.py index 2e70a3b7dc..56efb604b1 100644 --- a/lib/spack/spack/package_prefs.py +++ b/lib/spack/spack/package_prefs.py @@ -112,9 +112,17 @@ class PackagePrefs(object): # integer is the index of the first spec in order that satisfies # spec, or it's a number larger than any position in the order. - return next( + match_index = next( (i for i, s in enumerate(spec_order) if spec.satisfies(s)), len(spec_order)) + if match_index < len(spec_order) and spec_order[match_index] == spec: + # If this is called with multiple specs that all satisfy the same + # minimum index in spec_order, the one which matches that element + # of spec_order exactly is considered slightly better. Note + # that because this decreases the value by less than 1, it is not + # better than a match which occurs at an earlier index. + match_index -= 0.5 + return match_index @classproperty @classmethod diff --git a/lib/spack/spack/test/concretize_preferences.py b/lib/spack/spack/test/concretize_preferences.py index 5e880bc4d6..45c037eec7 100644 --- a/lib/spack/spack/test/concretize_preferences.py +++ b/lib/spack/spack/test/concretize_preferences.py @@ -102,6 +102,11 @@ class TestConcretizePreferences(object): spec = concretize('mpileaks') assert spec.version == spack.spec.Version('2.2') + def test_preferred_versions_mixed_version_types(self): + update_packages('mixedversions', 'version', ['2.0']) + spec = concretize('mixedversions') + assert spec.version == spack.spec.Version('2.0') + def test_preferred_providers(self): """Test preferred providers of virtual packages are applied correctly |