Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure valid version #124

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion robotpy_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,14 @@ def get_pypi_version(self, package: str, use_certifi: bool) -> Version:

# Sort the versions
maxv = Version(str(int(_WPILIB_YEAR) + 1))
versions = sorted(v for v in versions if v < maxv)

def _version_ok(v: Version) -> bool:
ok = v < maxv and not v.is_devrelease
if ok and not _IS_BETA:
ok = not v.is_prerelease
return ok

versions = sorted(v for v in versions if _version_ok(v))
if not versions:
raise InstallerException(f"could not find {package} version on pypi")

Expand Down
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
Loading