Skip to content

Commit

Permalink
Add support for cargo version range
Browse files Browse the repository at this point in the history
Signed-off-by: ziad <[email protected]>
  • Loading branch information
ziadhany committed Aug 29, 2022
2 parents 6ad300e + b74229c commit 9b0399b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ python:
- "3.9"

# Scripts to run at install stage
install: ./configure --dev
install: |
./configure --dev
source venv/bin/activate
# Scripts to run at script stage
script: venv/bin/pytest
script: pytest
24 changes: 18 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,56 @@ jobs:
image_name: ubuntu-18.04
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv/bin/pytest -n 2 -vvs
all: |
source venv/bin/activate
pytest -n 2 -vvs
- template: etc/ci/azure-posix.yml
parameters:
job_name: ubuntu20_cpython
image_name: ubuntu-20.04
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv/bin/pytest -n 2 -vvs
all: |
source venv/bin/activate
pytest -n 2 -vvs
- template: etc/ci/azure-posix.yml
parameters:
job_name: macos1015_cpython
image_name: macos-10.15
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv/bin/pytest -n 2 -vvs
all: |
source venv/bin/activate
pytest -n 2 -vvs
- template: etc/ci/azure-posix.yml
parameters:
job_name: macos11_cpython
image_name: macos-11
python_versions: ['3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv/bin/pytest -n 2 -vvs
all: |
source venv/bin/activate
pytest -n 2 -vvs
- template: etc/ci/azure-win.yml
parameters:
job_name: win2019_cpython
image_name: windows-2019
python_versions: ['3.6', '3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv\Scripts\pytest -n 2 -vvs
all: |
call venv\Scripts\activate.bat
pytest -n 2 -vvs
- template: etc/ci/azure-win.yml
parameters:
job_name: win2022_cpython
image_name: windows-2022
python_versions: ['3.7', '3.8', '3.9', '3.10']
test_suites:
all: venv\Scripts\pytest -n 2 -vvs
all: |
call venv\Scripts\activate.bat
pytest -n 2 -vvs
51 changes: 48 additions & 3 deletions src/univers/version_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ class NpmVersionRange(VersionRange):
">=": ">=",
"<": "<",
">": ">",
"=": "=", # This is not a native node-semver comparator, but is used in the gitlab version range for npm packages.
"=": "=",
# This is not a native node-semver comparator, but is used in the gitlab version range for npm packages.
}

@classmethod
Expand Down Expand Up @@ -672,7 +673,8 @@ class ComposerVersionRange(VersionRange):
">=": ">=",
"<": "<",
">": ">",
"=": "=", # This is not a native composer-semver comparator, but is used in the gitlab version range for composer packages.
"=": "=",
# This is not a native composer-semver comparator, but is used in the gitlab version range for composer packages.
}


Expand Down Expand Up @@ -774,7 +776,8 @@ class GolangVersionRange(VersionRange):
">=": ">=",
"<": "<",
">": ">",
"=": "=", # This is not a native golang-semver comparator, but is used in the gitlab version range for go packages.
"=": "=",
# This is not a native golang-semver comparator, but is used in the gitlab version range for go packages.
}


Expand All @@ -798,6 +801,48 @@ class HexVersionRange(VersionRange):
class CargoVersionRange(VersionRange):
scheme = "cargo"
version_class = versions.SemverVersion
vers_by_native_comparators = {
"==": "=", # not sure for this
"<=": "<=",
">=": ">=",
"<": "<",
">": ">",
}

@classmethod
def from_native(cls, string):
"""
Return a VersionRange built from an "cargo-semver" range ``string``.
>>> from univers.versions import SemverVersion
>>> constraints = [
... VersionConstraint(comparator=">=", version=SemverVersion('0.3.2')),
... ]
>>> assert CargoVersionRange(constraints=constraints) == CargoVersionRange.from_native(">= 0.3.2")
"""
try:
specifiers = SpecifierSet(string)
except InvalidSpecifier as e:
raise InvalidVersionRange() from e

constraints = []
unsupported_messages = []
for spec in specifiers:
operator = spec.operator
version = spec.version

try:
version = cls.version_class(version)
comparator = cls.vers_by_native_comparators[operator]
constraint = VersionConstraint(comparator=comparator, version=version)
constraints.append(constraint)
except:
msg = f"Invalid Semver version: {spec!r}"
unsupported_messages.append(msg)

if unsupported_messages:
raise InvalidVersionRange(*unsupported_messages)

return cls(constraints=constraints)


class MozillaVersionRange(VersionRange):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_codestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class BaseTests(unittest.TestCase):
def test_codestyle(self):
args = "venv/bin/black --check -l 100 setup.py src tests"
args = "black --check -l 100 setup.py src tests"
try:
subprocess.check_output(args.split())
except subprocess.CalledProcessError as e:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_skeleton_codestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_skeleton_codestyle(self):
if setup_cfg["metadata"]["name"] != "skeleton":
return

args = "venv/bin/black --check -l 100 setup.py etc tests"
args = "black --check -l 100 setup.py etc tests"
try:
subprocess.check_output(args.split())
except subprocess.CalledProcessError as e:
Expand Down

0 comments on commit 9b0399b

Please sign in to comment.