diff --git a/robotpy_installer/pyproject.py b/robotpy_installer/pyproject.py index aad6593..4793cb3 100644 --- a/robotpy_installer/pyproject.py +++ b/robotpy_installer/pyproject.py @@ -9,6 +9,7 @@ import tomli import tomlkit +from . import installer from . import pypackages from .pypackages import Packages, Env from .errors import Error @@ -22,6 +23,10 @@ class NoRobotpyError(PyprojectError): pass +class UnsupportedRobotpyVersion(PyprojectError): + pass + + def toml_path(project_path: pathlib.Path): return project_path / "pyproject.toml" @@ -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)) diff --git a/tests/test_pyproject.py b/tests/test_pyproject.py index 08d90fb..44f5fdb 100644 --- a/tests/test_pyproject.py +++ b/tests/test_pyproject.py @@ -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 @@ -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 ) == ( @@ -32,41 +33,43 @@ 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" ] @@ -74,7 +77,7 @@ def test_beta_empty_req(): ) 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( @@ -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'" @@ -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(