Skip to content

Commit 75474a1

Browse files
committed
add alpine support in univers
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 9c463ba commit 75474a1

10 files changed

Lines changed: 30 additions & 80 deletions

src/univers/debian.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ def compare_strings(version1, version2):
238238
- 0 means version1 and version2 are equal
239239
- 1 means version1 sorts after version2
240240
"""
241-
logger.debug(
242-
"Comparing Debian version number substrings %r and %r ..", version1, version2
243-
)
241+
logger.debug("Comparing Debian version number substrings %r and %r ..", version1, version2)
244242
mapping = characters_order
245243
v1 = list(version1)
246244
v2 = list(version2)

src/univers/gem.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ def split_segments(self):
345345
numeric_segments = []
346346
string_segments = []
347347
for seg in self.segments:
348-
is_numeric = isinstance(
349-
seg, int
350-
) # or (isinstance(seg, str) and seg.isdigit())
348+
is_numeric = isinstance(seg, int) # or (isinstance(seg, str) and seg.isdigit())
351349
if is_numeric:
352350
if string_segments:
353351
string_segments.append(seg)
@@ -491,9 +489,7 @@ def tilde_comparator(version, requirement, trace=False):
491489
according to the Rubygems tilde semantics.
492490
"""
493491
if trace:
494-
print(
495-
f" tilde_comparator: version: {version!r}, requirement: {requirement!r}"
496-
)
492+
print(f" tilde_comparator: version: {version!r}, requirement: {requirement!r}")
497493
print(f" version >= requirement: {version >= requirement!r}")
498494
print()
499495
print(
@@ -545,9 +541,7 @@ def __str__(self):
545541
return ", ".join(gcs)
546542

547543
def __repr__(self):
548-
gcs = ", ".join(
549-
repr(gc.to_string()) for gc in sort_constraints(self.constraints)
550-
)
544+
gcs = ", ".join(repr(gc.to_string()) for gc in sort_constraints(self.constraints))
551545
return f"GemRequirement({gcs})"
552546

553547
@classmethod

src/univers/maven.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,17 @@ def __init__(self, spec=None):
7878
if "," in _spec:
7979
lower_bound, upper_bound = _spec.split(",")
8080
if lower_bound and lower_bound == upper_bound:
81-
raise RestrictionParseError(
82-
"Range cannot have identical boundaries: %s" % spec
83-
)
81+
raise RestrictionParseError("Range cannot have identical boundaries: %s" % spec)
8482

8583
self.lower_bound = Version(lower_bound) if lower_bound else None
8684
self.upper_bound = Version(upper_bound) if upper_bound else None
8785

88-
if (
89-
self.lower_bound
90-
and self.upper_bound
91-
and self.upper_bound < self.lower_bound
92-
):
86+
if self.lower_bound and self.upper_bound and self.upper_bound < self.lower_bound:
9387
raise RestrictionParseError("Range defies version ordering: %s" % spec)
9488
else:
9589
# single version restriction
9690
if not self.lower_bound_inclusive or not self.upper_bound_inclusive:
97-
raise RestrictionParseError(
98-
"Single version must be surrounded by []: %s" % spec
99-
)
91+
raise RestrictionParseError("Single version must be surrounded by []: %s" % spec)
10092
version = Version(_spec)
10193
self.lower_bound = version
10294
self.upper_bound = version
@@ -139,9 +131,7 @@ def __cmp__(self, other):
139131
if result == 0:
140132
result = cmp(self.upper_bound, other.upper_bound)
141133
if result == 0:
142-
result = cmp(
143-
self.upper_bound_inclusive, other.upper_bound_inclusive
144-
)
134+
result = cmp(self.upper_bound_inclusive, other.upper_bound_inclusive)
145135
return result
146136

147137
def __eq__(self, other):
@@ -232,10 +222,7 @@ def __init__(self, spec):
232222
lower_bound = restriction.lower_bound
233223

234224
if upper_bound is not None:
235-
if (
236-
restriction.lower_bound is None
237-
or restriction.lower_bound < upper_bound
238-
):
225+
if restriction.lower_bound is None or restriction.lower_bound < upper_bound:
239226
raise VersionRangeParseError("Ranges overlap: %s" % spec)
240227
restrictions.append(restriction)
241228
upper_bound = restriction.upper_bound
@@ -248,8 +235,7 @@ def __init__(self, spec):
248235
if _spec:
249236
if restrictions:
250237
raise VersionRangeParseError(
251-
"Only fully-qualified sets allowed in multiple set"
252-
" scenario: %s" % spec
238+
"Only fully-qualified sets allowed in multiple set" " scenario: %s" % spec
253239
)
254240
else:
255241
version = Version(_spec)

src/univers/semver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def get_tilde_constraints(string, operator="~"):
5757
"""
5858
string = remove_spaces(string)
5959
if not string or not string.startswith(operator):
60-
raise ValueError(
61-
f"Invalid version range: {string!r} " f"does not start with {operator!r}"
62-
)
60+
raise ValueError(f"Invalid version range: {string!r} " f"does not start with {operator!r}")
6361

6462
version = string.lstrip(operator)
6563
lower_bound = SemverVersion(version)

src/univers/version_constraint.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def __attrs_post_init__(self):
9292
if self.version:
9393
object.__setattr__(self, "version_class", self.version.__class__)
9494
else:
95-
raise ValueError(
96-
"Cannot build a VersionConstraint without a version class"
97-
)
95+
raise ValueError("Cannot build a VersionConstraint without a version class")
9896

9997
def __str__(self):
10098
"""
@@ -342,8 +340,7 @@ def validate_comparators(constraints):
342340
c = "|".join(map(str, constraints))
343341
i = ", ".join(f"{x}|{y}" for x, y in invalid_equal)
344342
raise ValueError(
345-
f"Invalid {c!r}: where {i!r} "
346-
"cannot contain an equal = followed by either < or <="
343+
f"Invalid {c!r}: where {i!r} " "cannot contain an equal = followed by either < or <="
347344
)
348345

349346
# And ignoring all constraints with "=" or "!=" comparators:

src/univers/version_range.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ def from_string(cls, vers, simplify=False, validate=False):
107107
range_class = RANGE_CLASS_BY_SCHEMES.get(versioning_scheme)
108108
if not range_class:
109109
raise ValueError(
110-
f"{vers!r} has an unknown versioning scheme: "
111-
f"{versioning_scheme!r}.",
110+
f"{vers!r} has an unknown versioning scheme: " f"{versioning_scheme!r}.",
112111
)
113112

114113
version_class = range_class.version_class
@@ -522,15 +521,12 @@ def from_native(cls, string):
522521
# TODO: handle .* version, ~= and === operators
523522

524523
if ";" in string:
525-
raise InvalidVersionRange(
526-
f"Unsupported PyPI environment marker: {string!r}"
527-
)
524+
raise InvalidVersionRange(f"Unsupported PyPI environment marker: {string!r}")
528525

529526
unsupported_chars = ";<>!=\\/|{}()`?'\"\t\n "
530527
if any(c in string for c in unsupported_chars):
531528
raise InvalidVersionRange(
532-
f"Unsupported character: {unsupported_chars!r} "
533-
f"in PyPI version: {string!r}"
529+
f"Unsupported character: {unsupported_chars!r} " f"in PyPI version: {string!r}"
534530
)
535531

536532
try:
@@ -828,9 +824,7 @@ def from_native(cls, string):
828824
cleaned = remove_spaces(string).lower()
829825
if cleaned == "all":
830826
return cls(
831-
constraints=[
832-
VersionConstraint(comparator="*", version_class=cls.version_class)
833-
]
827+
constraints=[VersionConstraint(comparator="*", version_class=cls.version_class)]
834828
)
835829

836830
constraints = []
@@ -855,9 +849,7 @@ def from_native(cls, string):
855849
if is_stable:
856850
# we have a start and end in stable ranges
857851
start_version = cls.version_class(vs)
858-
end_version = cls.version_class(
859-
str(start_version.value.next_minor())
860-
)
852+
end_version = cls.version_class(str(start_version.value.next_minor()))
861853
vstart = VersionConstraint(comparator=">=", version=start_version)
862854
vend = VersionConstraint(comparator="<", version=end_version)
863855
constraints.extend([vstart, vend])

tests/test_codestyle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class BaseTests(unittest.TestCase):
1212
def test_codestyle(self):
13-
args = "venv/bin/black --check -l 100 setup.py etc src tests docs"
13+
args = "venv/bin/black --check -l 100 setup.py src tests"
1414
try:
1515
subprocess.check_output(args.split())
1616
except subprocess.CalledProcessError as e:
@@ -19,6 +19,6 @@ def test_codestyle(self):
1919
print("===========================================================")
2020
raise Exception(
2121
"Black style check failed; please format the code using:\n"
22-
" python -m black -l 100 setup.py etc src tests docs",
22+
" python -m black -l 100 setup.py src tests",
2323
e.output,
2424
) from e

tests/test_debian_version.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ def test_compare_versions(self):
151151
assert compare_versions("9.0.0", "10.0.0") == -1
152152

153153
assert compare_versions("1.2.3-1~deb7u1", "1.2.3-1") == -1
154-
assert (
155-
compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1")
156-
== -1
157-
)
154+
assert compare_versions("2.7.4+reloaded2-13ubuntu1", "2.7.4+reloaded2-13+deb9u1") == -1
158155
assert compare_versions("2.7.4+reloaded2-13", "2.7.4+reloaded2-13+deb9u1") == -1
159156

160157
# greater than
@@ -166,10 +163,7 @@ def test_compare_versions(self):
166163
assert compare_versions("9.0.0", "1.0.0") == 1
167164

168165
assert compare_versions("1.2.3-1", "1.2.3-1~deb7u1") == 1
169-
assert (
170-
compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1")
171-
== 1
172-
)
166+
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13ubuntu1") == 1
173167
assert compare_versions("2.7.4+reloaded2-13+deb9u1", "2.7.4+reloaded2-13") == 1
174168

175169
# unicode

tests/test_rubygems_gem_requirement.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
def test_equals():
1616
refute_requirement_equal("= 1.2", "= 1.3")
1717
refute_requirement_equal("~> 1.3", "~> 1.3.0")
18-
assert_requirement_equal(
19-
["> 2", "~> 1.3", "~> 1.3.1"], ["~> 1.3.1", "~> 1.3", "> 2"]
20-
)
18+
assert_requirement_equal(["> 2", "~> 1.3", "~> 1.3.1"], ["~> 1.3.1", "~> 1.3", "> 2"])
2119
assert_requirement_equal(["> 2", "~> 1.3"], ["> 2.0", "~> 1.3"])
2220

2321

@@ -329,9 +327,7 @@ def test_equivalent_requirements_are_equal():
329327
refute_requirement_equal("~> 1.3", "~> 1.3.0")
330328
refute_requirement_equal("~> 1.3.0", "~> 1.3")
331329

332-
assert_requirement_equal(
333-
["> 2", "~> 1.3", "~> 1.3.1"], ["~> 1.3.1", "~> 1.3", "> 2"]
334-
)
330+
assert_requirement_equal(["> 2", "~> 1.3", "~> 1.3.1"], ["~> 1.3.1", "~> 1.3", "> 2"])
335331

336332
assert_requirement_equal(["> 2", "~> 1.3"], ["> 2.0", "~> 1.3"])
337333
assert_requirement_equal(["> 2.0", "~> 1.3"], ["> 2", "~> 1.3"])

tests/test_version_range.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ class TestVersionRange(TestCase):
2121
def test_VersionRange_afrom_string(self):
2222
version_range = VersionRange.from_string("vers:pypi/>0.0.2")
2323
assert version_range == PypiVersionRange(
24-
constraints=[
25-
VersionConstraint(comparator=">", version=PypiVersion(string="0.0.2"))
26-
]
24+
constraints=[VersionConstraint(comparator=">", version=PypiVersion(string="0.0.2"))]
2725
)
2826

2927
def test_VersionRange_to_string(self):
3028
vers = "vers:pypi/0.0.2|0.0.6|>=0.0.0|0.0.1|0.0.4|0.0.5|0.0.3"
3129
version_range = VersionRange.from_string(vers)
3230
# note the sorting taking place
33-
assert (
34-
str(version_range)
35-
== "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6"
36-
)
31+
assert str(version_range) == "vers:pypi/>=0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6"
3732

3833
def test_VersionRange_pypi_does_not_contain_basic(self):
3934
vers = "vers:pypi/0.0.2|0.0.6|>=0.0.0|0.0.1|0.0.4|0.0.5|0.0.3"
@@ -94,9 +89,7 @@ def test_VersionRange_from_string_pypi(self):
9489
)
9590
assert version_range.constraints == expected
9691
# note the sorting taking place
97-
assert (
98-
str(version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6"
99-
)
92+
assert str(version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6"
10093

10194
version_range1 = VersionRange.from_string(vers, simplify=False, validate=True)
10295
assert version_range1.constraints == expected
@@ -126,7 +119,9 @@ def test_VersionRange_from_string_pypi_complex_simplify_and_validate(self):
126119
version_range = VersionRange.from_string(vers, simplify=True, validate=True)
127120

128121
def test_VersionRange_from_string_pypi_complex_simplify2(self):
129-
vers = "vers:pypi/>0.0.0|>=0.0.1|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|<=0.0.6|!=0.7|8.0|>12|<15.3"
122+
vers = (
123+
"vers:pypi/>0.0.0|>=0.0.1|>=0.0.1|0.0.2|0.0.3|0.0.4|<0.0.5|<=0.0.6|!=0.7|8.0|>12|<15.3"
124+
)
130125
version_range = VersionRange.from_string(vers, simplify=True)
131126
assert str(version_range) == "vers:pypi/>0.0.0|<=0.0.6|!=0.7|8.0|>12|<15.3"
132127

0 commit comments

Comments
 (0)