diff options
author | Wouter Deconinck <wdconinc@gmail.com> | 2024-09-02 05:42:15 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 10:42:15 +0000 |
commit | c47a3ee05b748c56425010cda8022e9af79d03ff (patch) | |
tree | 31d66e15f6df03ab47f9b7ab0c2908b70c7ae686 | |
parent | aaa7469b92be5d3c028a0aea5e27bd5bc074cad1 (diff) | |
download | spack-c47a3ee05b748c56425010cda8022e9af79d03ff.tar.gz spack-c47a3ee05b748c56425010cda8022e9af79d03ff.tar.bz2 spack-c47a3ee05b748c56425010cda8022e9af79d03ff.tar.xz spack-c47a3ee05b748c56425010cda8022e9af79d03ff.zip |
package_base: sort deprecated versions later in `preferred_version` (#46025)
-rw-r--r-- | lib/spack/spack/package_base.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/solver/asp.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/test/concretize.py | 2 |
3 files changed, 7 insertions, 8 deletions
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index 65c9e856bb..f3cbcbe4a6 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -116,11 +116,10 @@ def preferred_version(pkg: "PackageBase"): Arguments: pkg: The package whose versions are to be assessed. """ - # Here we sort first on the fact that a version is marked - # as preferred in the package, then on the fact that the - # version is not develop, then lexicographically - key_fn = lambda v: (pkg.versions[v].get("preferred", False), not v.isdevelop(), v) - return max(pkg.versions, key=key_fn) + from spack.solver.asp import concretization_version_order + + version, _ = max(pkg.versions.items(), key=concretization_version_order) + return version class WindowsRPath: diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py index 8a1933b749..9a36b0975b 100644 --- a/lib/spack/spack/solver/asp.py +++ b/lib/spack/spack/solver/asp.py @@ -579,7 +579,7 @@ def _is_checksummed_version(version_info: Tuple[GitOrStandardVersion, dict]): return _is_checksummed_git_version(version) -def _concretization_version_order(version_info: Tuple[GitOrStandardVersion, dict]): +def concretization_version_order(version_info: Tuple[GitOrStandardVersion, dict]): """Version order key for concretization, where preferred > not preferred, not deprecated > deprecated, finite > any infinite component; only if all are the same, do we use default version ordering.""" @@ -2026,7 +2026,7 @@ class SpackSolverSetup: # like being a "develop" version or being preferred exist only at a # package.py level, sort them in this partial list here package_py_versions = sorted( - pkg_cls.versions.items(), key=_concretization_version_order, reverse=True + pkg_cls.versions.items(), key=concretization_version_order, reverse=True ) if require_checksum and pkg_cls.has_code: diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py index eaef82930d..8e8e374fa8 100644 --- a/lib/spack/spack/test/concretize.py +++ b/lib/spack/spack/test/concretize.py @@ -2962,7 +2962,7 @@ def test_concretization_version_order(): result = [ v for v, _ in sorted( - versions, key=spack.solver.asp._concretization_version_order, reverse=True + versions, key=spack.solver.asp.concretization_version_order, reverse=True ) ] assert result == [ |