diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2021-10-27 11:58:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 02:58:04 -0700 |
commit | 2fd87046cd49a75d60aabaf3e502373e88dbc187 (patch) | |
tree | 2b0146d55e3633cd6f71ea068a753b9fd6bffc86 /lib | |
parent | ae6e83b1d5ef2e7049fbc01a7f308b4b5bdf4c4b (diff) | |
download | spack-2fd87046cd49a75d60aabaf3e502373e88dbc187.tar.gz spack-2fd87046cd49a75d60aabaf3e502373e88dbc187.tar.bz2 spack-2fd87046cd49a75d60aabaf3e502373e88dbc187.tar.xz spack-2fd87046cd49a75d60aabaf3e502373e88dbc187.zip |
Fix assumption v.concrete => isinstance(v, Version) (#26537)
* Add test
* Only extend with Git version when using Version
* xfail v.concrete test
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/spec.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/versions.py | 17 |
2 files changed, 23 insertions, 2 deletions
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 |