Skip to content

Commit 18e33ac

Browse files
authored
Merge branch 'main' into datetime-scheme
2 parents ec39593 + 6955566 commit 18e33ac

7 files changed

Lines changed: 74 additions & 8 deletions

File tree

.github/workflows/pypi-release.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
name: Release library as a PyPI wheel and sdist on tag
22

33
on:
4-
release:
5-
types: [created]
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "v*.*.*"
68

79
jobs:
810
build-and-publish-to-pypi:
911
name: Build and publish library to PyPI
10-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-22.04
1113
steps:
12-
- uses: actions/checkout@master
14+
- uses: actions/checkout@v4
1315
- name: Set up Python
14-
uses: actions/setup-python@v1
16+
uses: actions/setup-python@v5
1517
with:
1618
python-version: 3.9
1719
- name: Install pypa/build
1820
run: python -m pip install build --user
1921
- name: Build a binary wheel and a source tarball
2022
run: python -m build --sdist --wheel --outdir dist/
21-
.
2223
- name: Publish distribution to PyPI
2324
if: startsWith(github.ref, 'refs/tags')
24-
uses: pypa/gh-action-pypi-publish@master
25+
uses: pypa/gh-action-pypi-publish@release/v1
2526
with:
2627
password: ${{ secrets.PYPI_API_TOKEN }}
2728

CHANGELOG.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
Changelog
22
=========
33

4+
Version v31.1.1
5+
----------------
6+
7+
- Update CI, change run OS for Pypi release to 22.04
8+
9+
10+
Version v31.1.0
11+
----------------
12+
13+
- Introduce intdot versioning scheme
14+
- Add description to test fixture
15+
- Organize schema-based tests according to ecosystem
16+
- Use VERS test definition schema for tests
17+
418
Version v31.0.0
519
----------------
620

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = univers
3-
version = 31.0.0
3+
version = 31.1.0
44
license = Apache-2.0 AND BSD-3-Clause AND MIT
55

66
# description must be on ONE line https://github.com/pypa/setuptools/issues/1390

src/univers/version_range.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,11 @@ class NoneVersionRange(VersionRange):
12061206
version_class = versions.NoneVersion
12071207

12081208

1209+
class LexicographicVersionRange(VersionRange):
1210+
scheme = "lexicographic"
1211+
version_class = versions.LexicographicVersion
1212+
1213+
12091214
def from_gitlab_native(gitlab_scheme, string):
12101215
purl_scheme = gitlab_scheme
12111216
if gitlab_scheme not in PURL_TYPE_BY_GITLAB_SCHEME.values():
@@ -1452,6 +1457,7 @@ def build_range_from_snyk_advisory_string(scheme: str, string: Union[str, List])
14521457
"none": NoneVersionRange,
14531458
"intdot": IntdotVersionRange,
14541459
"datetime": DatetimeVersionRange,
1460+
"lexicographic": LexicographicVersionRange,
14551461
}
14561462

14571463
PURL_TYPE_BY_GITLAB_SCHEME = {

src/univers/versions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ def is_valid(cls, string):
147147
return string == "vers:none/*"
148148

149149

150+
class LexicographicVersion(Version):
151+
@classmethod
152+
def build_value(cls, string):
153+
return str(string)
154+
155+
"""
156+
Create a string, even if, e.g., an integer is given
157+
"""
158+
159+
@classmethod
160+
def normalize(cls, string):
161+
return remove_spaces(str(string))
162+
163+
def __lt__(self, other):
164+
return self.value.encode("utf-8") < other.value.encode("utf-8")
165+
166+
def __gt__(self, other):
167+
return self.value.encode("utf-8") > other.value.encode("utf-8")
168+
169+
def __eq__(self, other):
170+
return self.value.encode("utf-8") == other.value.encode("utf-8")
171+
172+
150173
class IntdotVersion(Version):
151174
@classmethod
152175
def build_value(cls, string):
@@ -738,4 +761,5 @@ def bump(self, index):
738761
AlpineLinuxVersion,
739762
IntdotVersion,
740763
DatetimeVersion,
764+
LexicographicVersion,
741765
]

tests/test_version_range.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from univers.version_range import from_gitlab_native
2525
from univers.versions import DatetimeVersion
2626
from univers.versions import IntdotVersion
27+
from univers.versions import LexicographicVersion
2728
from univers.versions import OpensslVersion
2829
from univers.versions import PypiVersion
2930
from univers.versions import SemverVersion
@@ -408,3 +409,12 @@ def test_version_range_datetime():
408409
assert DatetimeVersion("2001-01-01T01:02:03Z") in datetime_constraints
409410
with pytest.raises(Exception):
410411
VersionRange.from_string("vers:datetime/2025-08-25")
412+
413+
414+
def test_version_range_lexicographic():
415+
assert LexicographicVersion("1.2.3") in VersionRange.from_string(
416+
"vers:lexicographic/<1.2.4|>0.9"
417+
)
418+
assert LexicographicVersion(-123) in VersionRange.from_string("vers:lexicographic/<~")
419+
assert LexicographicVersion(None) in VersionRange.from_string("vers:lexicographic/*")
420+
assert LexicographicVersion("ABC") in VersionRange.from_string("vers:lexicographic/>abc|<=None")

tests/test_versions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from univers.versions import GentooVersion
1515
from univers.versions import GolangVersion
1616
from univers.versions import IntdotVersion
17+
from univers.versions import LexicographicVersion
1718
from univers.versions import MavenVersion
1819
from univers.versions import NginxVersion
1920
from univers.versions import NugetVersion
@@ -242,3 +243,13 @@ def test_datetime_version():
242243
assert DatetimeVersion("2023-10-28T19:30:00+01:00") == DatetimeVersion("2023-10-28T18:30:00Z")
243244
assert not DatetimeVersion.is_valid("2023-10-28Z19:30:00+01:00")
244245
assert not DatetimeVersion.is_valid("10-10-2023T19:30:00+01:00")
246+
247+
248+
def test_lexicographic_version():
249+
assert LexicographicVersion("abc") == LexicographicVersion("abc")
250+
assert LexicographicVersion(" abc") == LexicographicVersion("abc")
251+
assert LexicographicVersion("123") == LexicographicVersion(123)
252+
assert LexicographicVersion("abc") > LexicographicVersion(None)
253+
assert LexicographicVersion("Abc") < LexicographicVersion(None)
254+
assert LexicographicVersion("123") < LexicographicVersion("bbc")
255+
assert LexicographicVersion("2.3.4") > LexicographicVersion("1.2.3")

0 commit comments

Comments
 (0)