diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2021-10-01 21:23:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-01 12:23:26 -0700 |
commit | 50feaae81c1bee1f459f25c8c224cd3ec3129728 (patch) | |
tree | e393412a76571c236e10f02d883570f9a4413564 | |
parent | bce269df1377711e891760fe21b008aac0dea2b0 (diff) | |
download | spack-50feaae81c1bee1f459f25c8c224cd3ec3129728.tar.gz spack-50feaae81c1bee1f459f25c8c224cd3ec3129728.tar.bz2 spack-50feaae81c1bee1f459f25c8c224cd3ec3129728.tar.xz spack-50feaae81c1bee1f459f25c8c224cd3ec3129728.zip |
Allow non-empty ranges 1.1.0:1.1 (#26402)
-rw-r--r-- | lib/spack/spack/test/versions.py | 14 | ||||
-rw-r--r-- | lib/spack/spack/version.py | 11 |
2 files changed, 23 insertions, 2 deletions
diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py index a3d11108ef..8a6fd77d8b 100644 --- a/lib/spack/spack/test/versions.py +++ b/lib/spack/spack/test/versions.py @@ -16,7 +16,7 @@ from llnl.util.filesystem import working_dir import spack.package import spack.spec from spack.util.executable import which -from spack.version import Version, VersionList, ver +from spack.version import Version, VersionList, VersionRange, ver def assert_ver_lt(a, b): @@ -602,3 +602,15 @@ def test_versions_from_git(mock_git_version_info, monkeypatch, mock_packages): expected = f.read() assert str(comparator) == expected + + +def test_version_range_nonempty(): + assert Version('1.2.9') in VersionRange('1.2.0', '1.2') + assert Version('1.1.1') in ver('1.0:1') + + +def test_empty_version_range_raises(): + with pytest.raises(ValueError): + assert VersionRange('2', '1.0') + with pytest.raises(ValueError): + assert ver('2:1.0') diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py index 9aad046f25..13fb798dfe 100644 --- a/lib/spack/spack/version.py +++ b/lib/spack/spack/version.py @@ -500,7 +500,16 @@ class VersionRange(object): self.start = start self.end = end - if start and end and end < start: + + # Unbounded ranges are not empty + if not start or not end: + return + + # Do not allow empty ranges. We have to be careful about lexicographical + # ordering of versions here: 1.2 < 1.2.3 lexicographically, but 1.2.3:1.2 + # means the range [1.2.3, 1.3), which is non-empty. + min_len = min(len(start), len(end)) + if end.up_to(min_len) < start.up_to(min_len): raise ValueError("Invalid Version range: %s" % self) def lowest(self): |