44#
55# Visit https://aboutcode.org and https://github.com/nexB/univers for support and download.
66
7- import semantic_version
8-
97from univers .utils import remove_spaces
108from univers .version_constraint import VersionConstraint
9+ from univers .versions import SemverVersion
1110
1211"""
1312node-semver and Rubygems semver-like related utilities.
1615
1716def get_caret_constraints (string ):
1817 """
19- Return a tuple of two VersionConstraint representing the lower and upper
20- bound of version constraint ``string`` that contains a caret node-semver-
21- like range. Raise a ValueError if this is not a caret range.
18+ Return a tuple of two VersionConstraint of ``SemverVersion`` representing
19+ the lower and upper bound of version constraint ``string`` that contains a
20+ caret node-semver- like range. Raise a ValueError if this is not a caret
21+ range.
2222
2323 For example:
2424 >>> lower_bound, upper_bound = get_caret_constraints("^1.0.2")
25- >>> vlow = semantic_version.Version ("1.0.2")
26- >>> vup = semantic_version.Version ("2.0.0")
25+ >>> vlow = SemverVersion ("1.0.2")
26+ >>> vup = SemverVersion ("2.0.0")
2727 >>> assert lower_bound == VersionConstraint(comparator=">=", version=vlow)
2828 >>> assert upper_bound == VersionConstraint(comparator="<", version=vup)
2929 """
@@ -32,8 +32,8 @@ def get_caret_constraints(string):
3232 raise ValueError (f"Invalid caret version range: { string !r} " )
3333
3434 version = string .lstrip ("^" )
35- lower_bound = semantic_version . Version (version )
36- upper_bound = lower_bound .next_major ()
35+ lower_bound = SemverVersion (version )
36+ upper_bound = SemverVersion ( str ( lower_bound .value . next_major ()) )
3737
3838 return (
3939 VersionConstraint (comparator = ">=" , version = lower_bound ),
@@ -43,14 +43,15 @@ def get_caret_constraints(string):
4343
4444def get_tilde_constraints (string , operator = "~" ):
4545 """
46- Return a tuple of two VersionConstraint representing the lower and upper
47- bound of a version range ``string`` that contains a tilde node-semver-like
48- range. Raise a ValueError if this is not a tilde range.
46+ Return a tuple of two VersionConstraint of ``SemverVersion`` representing
47+ the lower and upper bound of a version range ``string`` that contains a
48+ tilde node-semver-like range.
49+ Raise a ValueError if this is not a tilde range.
4950
5051 For example:
5152 >>> lower_bound, upper_bound = get_tilde_constraints("~1.0.2")
52- >>> vlow = semantic_version.Version ("1.0.2")
53- >>> vup = semantic_version.Version ("1.1.0")
53+ >>> vlow = SemverVersion ("1.0.2")
54+ >>> vup = SemverVersion ("1.1.0")
5455 >>> assert lower_bound == VersionConstraint(comparator=">=", version=vlow)
5556 >>> assert upper_bound == VersionConstraint(comparator="<", version=vup)
5657 """
@@ -59,8 +60,8 @@ def get_tilde_constraints(string, operator="~"):
5960 raise ValueError (f"Invalid version range: { string !r} " f"does not start with { operator !r} " )
6061
6162 version = string .lstrip (operator )
62- lower_bound = semantic_version . Version (version )
63- upper_bound = lower_bound .next_minor ()
63+ lower_bound = SemverVersion (version )
64+ upper_bound = SemverVersion ( str ( lower_bound .value . next_minor ()) )
6465
6566 return (
6667 VersionConstraint (comparator = ">=" , version = lower_bound ),
@@ -71,14 +72,15 @@ def get_tilde_constraints(string, operator="~"):
7172# FIXME: this is unlikely correct https://github.com/npm/node-semver/issues/112
7273def get_pessimistic_constraints (string ):
7374 """
74- Return a tuple of two VersionConstraint representing the lower and upper
75- bound of version range ``string`` that contains a pessimistic Ruby range.
76- Raise a ValueError if this is not a pessimistic Rubygems range.
75+ Return a tuple of two VersionConstraint of ``SemverVersion`` representing
76+ the lower and upper bound of version range ``string`` that contains a
77+ pessimistic Ruby range. Raise a ValueError if this is not a pessimistic
78+ Rubygems range.
7779
7880 For example:
7981 >>> lower_bound, upper_bound = get_pessimistic_constraints("~>2.0.8")
80- >>> vlow = semantic_version.Version ("2.0.8")
81- >>> vup = semantic_version.Version ("2.1.0")
82+ >>> vlow = SemverVersion ("2.0.8")
83+ >>> vup = SemverVersion ("2.1.0")
8284 >>> assert lower_bound == VersionConstraint(comparator=">=", version=vlow)
8385 >>> assert upper_bound == VersionConstraint(comparator="<", version=vup)
8486 """
0 commit comments