From 2fd87046cd49a75d60aabaf3e502373e88dbc187 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 27 Oct 2021 11:58:04 +0200 Subject: Fix assumption v.concrete => isinstance(v, Version) (#26537) * Add test * Only extend with Git version when using Version * xfail v.concrete test --- lib/spack/spack/spec.py | 8 ++++++-- lib/spack/spack/test/versions.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index a153ffe50f..692c7522f3 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -4754,8 +4754,12 @@ class SpecParser(spack.parse.Parser): # Generate lookups for git-commit-based versions for spec in specs: # Cannot do lookups for versions in anonymous specs - # Only allow concrete versions using git for now - if spec.name and spec.versions.concrete and spec.version.is_commit: + # Only allow Version objects to use git for now + # Note: VersionRange(x, x) is currently concrete, hence isinstance(...). + if ( + spec.name and spec.versions.concrete and + isinstance(spec.version, vn.Version) and spec.version.is_commit + ): pkg = spec.package if hasattr(pkg, 'git'): spec.version.generate_commit_lookup(pkg) diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index ee2a885306..aec9402243 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -628,3 +628,20 @@ def test_version_wrong_idx_type(): v = Version('1.1') with pytest.raises(TypeError): v['0:'] + + +@pytest.mark.regression('26482') +def test_version_list_with_range_included_in_concrete_version_interpreted_as_range(): + # Note: this test only tests whether we can construct a version list of a range + # and a version, where the range is contained in the version when it is interpreted + # as a range. That is: Version('3.1') interpreted as VersionRange('3.1', '3.1'). + # Cleary it *shouldn't* be interpreted that way, but that is how Spack currently + # behaves, and this test only ensures that creating a VersionList of this type + # does not throw like reported in the linked Github issue. + VersionList([Version('3.1'), VersionRange('3.1.1', '3.1.2')]) + + +@pytest.mark.xfail +def test_version_list_with_range_and_concrete_version_is_not_concrete(): + v = VersionList([Version('3.1'), VersionRange('3.1.1', '3.1.2')]) + assert v.concrete -- cgit v1.2.3-60-g2f50