Skip to content

Commit

Permalink
Use from_versions for getting vers from discrete versions
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jul 24, 2024
1 parent 8f0d727 commit 3d0de11
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
30 changes: 0 additions & 30 deletions src/univers/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,36 +1377,6 @@ def build_range_from_snyk_advisory_string(scheme: str, string: Union[str, List])
return vrc(constraints=version_constraints)


def build_range_from_discrete_version_string(scheme: str, string: Union[str, List]):
"""
Return VersionRange computed from discrete versions.
Discrete version range looks like:
["1.5","3.1.2","3.1-beta"]
For example::
# >>> vr = build_constraints_from_discrete_version_string("pypi", ["1.5","3.1.2","3.1-beta"])
# >>> assert str(vr) == "vers:pypi/1.5|3.1-beta|3.1.2"
# >>> vr = build_constraints_from_discrete_version_string("pypi","9.21")
# >>> assert str(vr) == "vers:pypi/9.21"
"""
version_constraints = []
vrc = RANGE_CLASS_BY_SCHEMES[scheme]

if isinstance(string, str):
string = [string]

for item in string:
version = item.strip()
version = vrc.version_class(version)
version_constraints.append(
VersionConstraint(
version=version,
)
)
return vrc(constraints=version_constraints)


RANGE_CLASS_BY_SCHEMES = {
"npm": NpmVersionRange,
"deb": DebianVersionRange,
Expand Down
9 changes: 0 additions & 9 deletions tests/test_version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from univers.version_range import OpensslVersionRange
from univers.version_range import PypiVersionRange
from univers.version_range import VersionRange
from univers.version_range import build_range_from_discrete_version_string
from univers.version_range import build_range_from_snyk_advisory_string
from univers.version_range import from_gitlab_native
from univers.versions import InvalidVersion
Expand Down Expand Up @@ -489,14 +488,6 @@ def test_build_range_from_snyk_advisory_string_spaced():
assert str(vr) == expected


def test_build_range_from_discrete_version_string():
expression = ["4.1.0", " 4.4.1", "2.1.0 ", " 3.2.7 "]
vr = build_range_from_discrete_version_string("pypi", expression)
expected = "vers:pypi/2.1.0|3.2.7|4.1.0|4.4.1"

assert str(vr) == expected


def test_version_range_normalize_case1():
known_versions = ["4.0.0", "3.0.0", "1.0.0", "2.0.0", "1.3.0", "1.1.0", "1.2.0"]

Expand Down

0 comments on commit 3d0de11

Please sign in to comment.