Allow non-empty ranges 1.1.0:1.1 (#26402)
This commit is contained in:
parent
bce269df13
commit
50feaae81c
2 changed files with 23 additions and 2 deletions
|
@ -16,7 +16,7 @@
|
|||
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')
|
||||
|
|
|
@ -500,7 +500,16 @@ def __init__(self, start, end):
|
|||
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue