Skip to content

Commit

Permalink
Merge pull request #124 from robotpy/ensure-valid-version
Browse files Browse the repository at this point in the history
Ensure valid version
  • Loading branch information
virtuald authored Dec 12, 2024
2 parents 88a4946 + 400d51c commit 1ee4aaf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
13 changes: 13 additions & 0 deletions robotpy_installer/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tomli
import tomlkit

from . import installer
from . import pypackages
from .pypackages import Packages, Env
from .errors import Error
Expand All @@ -22,6 +23,10 @@ class NoRobotpyError(PyprojectError):
pass


class UnsupportedRobotpyVersion(PyprojectError):
pass


def toml_path(project_path: pathlib.Path):
return project_path / "pyproject.toml"

Expand Down Expand Up @@ -223,6 +228,14 @@ def _load(
f"{pyproject_path}: tools.robotpy.robotpy_version is not a valid version"
) from None

supported_year = int(installer._WPILIB_YEAR)
if robotpy_version.major != supported_year:
msg = (
f"Only RobotPy {supported_year}.x is supported by this version "
f"of robotpy-installer ({pyproject_path} has {robotpy_version})"
)
raise UnsupportedRobotpyVersion(msg)

robotpy_extras_any = robotpy_data.get("robotpy_extras")
if isinstance(robotpy_extras_any, list):
robotpy_extras = list(map(str, robotpy_extras_any))
Expand Down
37 changes: 20 additions & 17 deletions tests/test_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing

from robotpy_installer import pyproject, pypackages
from robotpy_installer.installer import _WPILIB_YEAR as YEAR

from packaging.requirements import Requirement

Expand All @@ -16,12 +17,12 @@ def null_resolver(req: Requirement, env: pypackages.Env) -> typing.List[Requirem

def test_ok():
project = load_project(
"""
f"""
[tool.robotpy]
robotpy_version = "2024.1.1.2"
robotpy_version = "{YEAR}.1.1.2"
"""
)
installed = pypackages.make_packages({"robotpy": "2024.1.1.2"})
installed = pypackages.make_packages({"robotpy": f"{YEAR}.1.1.2"})
assert project.are_requirements_met(
installed, pypackages.roborio_env(), null_resolver
) == (
Expand All @@ -32,49 +33,51 @@ def test_ok():

def test_older_fail():
project = load_project(
"""
f"""
[tool.robotpy]
robotpy_version = "2024.1.1.2"
robotpy_version = "{YEAR}.1.1.2"
"""
)
installed = pypackages.make_packages({"robotpy": "2024.1.1.0"})
installed = pypackages.make_packages({"robotpy": f"{YEAR}.1.1.0"})
assert project.are_requirements_met(
installed, pypackages.roborio_env(), null_resolver
) == (
False,
["robotpy==2024.1.1.2 (found 2024.1.1.0)"],
[f"robotpy=={YEAR}.1.1.2 (found {YEAR}.1.1.0)"],
)


def test_older_and_newer_fail():
project = load_project(
"""
f"""
[tool.robotpy]
robotpy_version = "2024.1.1.2"
robotpy_version = "{YEAR}.1.1.2"
"""
)
installed = pypackages.make_packages({"robotpy": ["2024.1.1.0", "2024.1.1.4"]})
installed = pypackages.make_packages(
{"robotpy": [f"{YEAR}.1.1.0", f"{YEAR}.1.1.4"]}
)
assert project.are_requirements_met(
installed, pypackages.roborio_env(), null_resolver
) == (
False,
["robotpy==2024.1.1.2 (found 2024.1.1.0, 2024.1.1.4)"],
[f"robotpy=={YEAR}.1.1.2 (found {YEAR}.1.1.0, {YEAR}.1.1.4)"],
)


def test_beta_empty_req():
project = load_project(
"""
f"""
[tool.robotpy]
robotpy_version = "2024.1.1.2"
robotpy_version = "{YEAR}.1.1.2"
requires = [
"robotpy-commands-v2"
]
"""
)

installed = pypackages.make_packages(
{"robotpy": "2024.1.1.2", "robotpy-commands-v2": "2024.0.0b4"}
{"robotpy": f"{YEAR}.1.1.2", "robotpy-commands-v2": f"{YEAR}.0.0b4"}
)

assert project.are_requirements_met(
Expand All @@ -87,9 +90,9 @@ def test_beta_empty_req():

def test_env_marker():
project = load_project(
"""
f"""
[tool.robotpy]
robotpy_version = "2024.1.1.2"
robotpy_version = "{YEAR}.1.1.2"
requires = [
"robotpy-opencv; platform_machine == 'roborio'",
"opencv-python; platform_machine != 'roborio'"
Expand All @@ -98,7 +101,7 @@ def test_env_marker():
)

installed = pypackages.make_packages(
{"robotpy": "2024.1.1.2", "robotpy-opencv": "2024.0.0"}
{"robotpy": f"{YEAR}.1.1.2", "robotpy-opencv": f"{YEAR}.0.0"}
)

assert project.are_requirements_met(
Expand Down

0 comments on commit 1ee4aaf

Please sign in to comment.