Skip to content

Commit 03c7cc7

Browse files
committed
add all and none versioning schemes, add range tests
1 parent 9c15915 commit 03c7cc7

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/univers/version_range.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from univers import versions
2020
from univers.conan.version_range import VersionRange as conan_version_range
2121
from univers.utils import remove_spaces
22+
from univers.versions import AllVersion
23+
from univers.versions import NoneVersion
2224
from univers.version_constraint import VersionConstraint
2325
from univers.version_constraint import contains_version
2426

@@ -220,6 +222,13 @@ def __contains__(self, version):
220222
object. A version is contained in a VersionRange if it satisfies its
221223
constraints according to ``vers`` rules.
222224
"""
225+
226+
if self.version_class is AllVersion:
227+
return True
228+
229+
if self.version_class is NoneVersion:
230+
return False
231+
223232
if not isinstance(version, self.version_class):
224233
raise TypeError(
225234
f"{version!r} is not of expected type: {self.version_class!r}",
@@ -712,9 +721,9 @@ class PypiVersionRange(VersionRange):
712721
def from_native(cls, string):
713722
"""
714723
Return a VersionRange built from a PyPI PEP440 version specifiers ``string``.
715-
Raise an a univers.versions.InvalidVersion
724+
Raise a univers.versions.InvalidVersion
716725
"""
717-
# TODO: environment markers are yet supported
726+
# TODO: environment markers are not yet supported
718727
# TODO: handle .* version, ~= and === operators
719728

720729
if ";" in string:
@@ -1177,6 +1186,16 @@ class MattermostVersionRange(VersionRange):
11771186
version_class = versions.SemverVersion
11781187

11791188

1189+
class AllVersionRange(VersionRange):
1190+
scheme = "all"
1191+
version_class = versions.AllVersion
1192+
1193+
1194+
class NoneVersionRange(VersionRange):
1195+
scheme = "none"
1196+
version_class = versions.NoneVersion
1197+
1198+
11801199
def from_gitlab_native(gitlab_scheme, string):
11811200
purl_scheme = gitlab_scheme
11821201
if gitlab_scheme not in PURL_TYPE_BY_GITLAB_SCHEME.values():
@@ -1419,6 +1438,8 @@ def build_range_from_snyk_advisory_string(scheme: str, string: Union[str, List])
14191438
"openssl": OpensslVersionRange,
14201439
"mattermost": MattermostVersionRange,
14211440
"conan": ConanVersionRange,
1441+
"all": AllVersionRange,
1442+
"none": NoneVersionRange,
14221443
}
14231444

14241445
PURL_TYPE_BY_GITLAB_SCHEME = {

src/univers/versions.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def build_value(self, string):
123123

124124
def satisfies(self, constraint):
125125
"""
126-
Return True is this Version satisfies the ``constraint``
126+
Return True if this Version satisfies the ``constraint``
127127
VersionConstraint. Satisfying means that this version is "within" the
128128
``constraint``.
129129
"""
@@ -133,6 +133,14 @@ def __str__(self):
133133
return str(self.value)
134134

135135

136+
class AllVersion(Version):
137+
pass
138+
139+
140+
class NoneVersion(Version):
141+
pass
142+
143+
136144
class GenericVersion(Version):
137145
@classmethod
138146
def is_valid(cls, string):

tests/test_version_range.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from univers.versions import PypiVersion
2929
from univers.versions import RubygemsVersion
3030
from univers.versions import SemverVersion
31+
from univers.versions import Version
3132

3233

3334
class TestVersionRange(TestCase):
@@ -546,3 +547,13 @@ def test_version_range_normalize_case3():
546547
nvr = vr.normalize(known_versions=known_versions)
547548

548549
assert str(nvr) == "vers:pypi/>=1.0.0|<=1.3.0|3.0.0"
550+
551+
def test_version_range_all():
552+
all_vers = VersionRange.from_string("vers:all/*")
553+
assert all_vers.contains(Version("1.2.3"))
554+
assert PypiVersion("2.0.3") in all_vers
555+
556+
def test_version_range_none():
557+
all_vers = VersionRange.from_string("vers:none/*")
558+
assert not all_vers.contains(Version("1.2.3"))
559+
assert PypiVersion("2.0.3") not in all_vers

0 commit comments

Comments
 (0)