Skip to content

Commit 9b0399b

Browse files
committed
Add support for cargo version range
Signed-off-by: ziad <ziadhany2016@gmail.com>
2 parents 6ad300e + b74229c commit 9b0399b

File tree

5 files changed

+72
-13
lines changed

5 files changed

+72
-13
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ python:
1616
- "3.9"
1717

1818
# Scripts to run at install stage
19-
install: ./configure --dev
19+
install: |
20+
./configure --dev
21+
source venv/bin/activate
2022
2123
# Scripts to run at script stage
22-
script: venv/bin/pytest
24+
script: pytest

azure-pipelines.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,56 @@ jobs:
1313
image_name: ubuntu-18.04
1414
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
1515
test_suites:
16-
all: venv/bin/pytest -n 2 -vvs
16+
all: |
17+
source venv/bin/activate
18+
pytest -n 2 -vvs
1719
1820
- template: etc/ci/azure-posix.yml
1921
parameters:
2022
job_name: ubuntu20_cpython
2123
image_name: ubuntu-20.04
2224
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
2325
test_suites:
24-
all: venv/bin/pytest -n 2 -vvs
26+
all: |
27+
source venv/bin/activate
28+
pytest -n 2 -vvs
2529
2630
- template: etc/ci/azure-posix.yml
2731
parameters:
2832
job_name: macos1015_cpython
2933
image_name: macos-10.15
3034
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
3135
test_suites:
32-
all: venv/bin/pytest -n 2 -vvs
36+
all: |
37+
source venv/bin/activate
38+
pytest -n 2 -vvs
3339
3440
- template: etc/ci/azure-posix.yml
3541
parameters:
3642
job_name: macos11_cpython
3743
image_name: macos-11
3844
python_versions: ['3.7', '3.8', '3.9', '3.10']
3945
test_suites:
40-
all: venv/bin/pytest -n 2 -vvs
46+
all: |
47+
source venv/bin/activate
48+
pytest -n 2 -vvs
4149
4250
- template: etc/ci/azure-win.yml
4351
parameters:
4452
job_name: win2019_cpython
4553
image_name: windows-2019
4654
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
4755
test_suites:
48-
all: venv\Scripts\pytest -n 2 -vvs
56+
all: |
57+
call venv\Scripts\activate.bat
58+
pytest -n 2 -vvs
4959
5060
- template: etc/ci/azure-win.yml
5161
parameters:
5262
job_name: win2022_cpython
5363
image_name: windows-2022
5464
python_versions: ['3.7', '3.8', '3.9', '3.10']
5565
test_suites:
56-
all: venv\Scripts\pytest -n 2 -vvs
66+
all: |
67+
call venv\Scripts\activate.bat
68+
pytest -n 2 -vvs

src/univers/version_range.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ class NpmVersionRange(VersionRange):
233233
">=": ">=",
234234
"<": "<",
235235
">": ">",
236-
"=": "=", # This is not a native node-semver comparator, but is used in the gitlab version range for npm packages.
236+
"=": "=",
237+
# This is not a native node-semver comparator, but is used in the gitlab version range for npm packages.
237238
}
238239

239240
@classmethod
@@ -672,7 +673,8 @@ class ComposerVersionRange(VersionRange):
672673
">=": ">=",
673674
"<": "<",
674675
">": ">",
675-
"=": "=", # This is not a native composer-semver comparator, but is used in the gitlab version range for composer packages.
676+
"=": "=",
677+
# This is not a native composer-semver comparator, but is used in the gitlab version range for composer packages.
676678
}
677679

678680

@@ -774,7 +776,8 @@ class GolangVersionRange(VersionRange):
774776
">=": ">=",
775777
"<": "<",
776778
">": ">",
777-
"=": "=", # This is not a native golang-semver comparator, but is used in the gitlab version range for go packages.
779+
"=": "=",
780+
# This is not a native golang-semver comparator, but is used in the gitlab version range for go packages.
778781
}
779782

780783

@@ -798,6 +801,48 @@ class HexVersionRange(VersionRange):
798801
class CargoVersionRange(VersionRange):
799802
scheme = "cargo"
800803
version_class = versions.SemverVersion
804+
vers_by_native_comparators = {
805+
"==": "=", # not sure for this
806+
"<=": "<=",
807+
">=": ">=",
808+
"<": "<",
809+
">": ">",
810+
}
811+
812+
@classmethod
813+
def from_native(cls, string):
814+
"""
815+
Return a VersionRange built from an "cargo-semver" range ``string``.
816+
>>> from univers.versions import SemverVersion
817+
>>> constraints = [
818+
... VersionConstraint(comparator=">=", version=SemverVersion('0.3.2')),
819+
... ]
820+
>>> assert CargoVersionRange(constraints=constraints) == CargoVersionRange.from_native(">= 0.3.2")
821+
"""
822+
try:
823+
specifiers = SpecifierSet(string)
824+
except InvalidSpecifier as e:
825+
raise InvalidVersionRange() from e
826+
827+
constraints = []
828+
unsupported_messages = []
829+
for spec in specifiers:
830+
operator = spec.operator
831+
version = spec.version
832+
833+
try:
834+
version = cls.version_class(version)
835+
comparator = cls.vers_by_native_comparators[operator]
836+
constraint = VersionConstraint(comparator=comparator, version=version)
837+
constraints.append(constraint)
838+
except:
839+
msg = f"Invalid Semver version: {spec!r}"
840+
unsupported_messages.append(msg)
841+
842+
if unsupported_messages:
843+
raise InvalidVersionRange(*unsupported_messages)
844+
845+
return cls(constraints=constraints)
801846

802847

803848
class MozillaVersionRange(VersionRange):

tests/test_codestyle.py

Lines changed: 1 addition & 1 deletion
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 src tests"
13+
args = "black --check -l 100 setup.py src tests"
1414
try:
1515
subprocess.check_output(args.split())
1616
except subprocess.CalledProcessError as e:

tests/test_skeleton_codestyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_skeleton_codestyle(self):
2222
if setup_cfg["metadata"]["name"] != "skeleton":
2323
return
2424

25-
args = "venv/bin/black --check -l 100 setup.py etc tests"
25+
args = "black --check -l 100 setup.py etc tests"
2626
try:
2727
subprocess.check_output(args.split())
2828
except subprocess.CalledProcessError as e:

0 commit comments

Comments
 (0)