diff --git a/robotpy_installer/_pipstub.py b/robotpy_installer/_pipstub.py index 3a78d51..0ae039c 100644 --- a/robotpy_installer/_pipstub.py +++ b/robotpy_installer/_pipstub.py @@ -12,33 +12,42 @@ import os import sys -# TODO: better detection needed to ensure we only run this on systemcore -# but this is fine for now? -if sysconfig.get_platform() == "linux-aarch64": - try: - import pip._vendor.packaging.tags as tags +_ROBOTPY_PYTHON_PLATFORM = "linux_systemcore" +_ROBOTPY_PYTHON_VERSION_TUPLE_FULL = (3, 14, 3) +_ROBOTPY_MANYLINUX_MIN = 17 +_ROBOTPY_MANYLINUX_MAX = 38 - def platform_tags(): - for i in reversed(range(17, 38)): - yield f"manylinux_2_{i}_aarch64" +if __name__ == "__main__": - yield "linux_systemcore" - yield "linux_aarch64" + # TODO: better detection needed to ensure we only run this on systemcore + # but this is fine for now? + if sysconfig.get_platform() == "linux-aarch64": + try: + import pip._vendor.packaging.tags as tags - tags.platform_tags = platform_tags + def platform_tags(): + for i in reversed( + range(_ROBOTPY_MANYLINUX_MIN, _ROBOTPY_MANYLINUX_MAX + 1) + ): + yield f"manylinux_2_{i}_aarch64" - except ImportError: - pass + yield _ROBOTPY_PYTHON_PLATFORM + yield "linux_aarch64" + tags.platform_tags = platform_tags + + except ImportError: + pass -if __name__ == "__main__": # Setup environment for what the SystemCore python would have # -> strictly speaking we only care about platform.machine as that's what # we're using in robotpy-meta, but the rest for completeness - sysconfig.get_platform = lambda: "linux-systemcore" + sysconfig.get_platform = lambda: _ROBOTPY_PYTHON_PLATFORM.replace("_", "-") platform.machine = lambda: "systemcore" platform.python_implementation = lambda: "CPython" platform.system = lambda: "Linux" - platform.python_version = lambda: "3.14.0" + platform.python_version = lambda: ".".join( + map(str, _ROBOTPY_PYTHON_VERSION_TUPLE_FULL) + ) runpy.run_module("pip", run_name="__main__") diff --git a/robotpy_installer/installer.py b/robotpy_installer/installer.py index 3567b53..90d5865 100755 --- a/robotpy_installer/installer.py +++ b/robotpy_installer/installer.py @@ -36,7 +36,8 @@ ] _ROBOTPY_PYTHON_PLATFORM = "linux_systemcore" -_ROBOTPY_PYTHON_VERSION_TUPLE = (3, 14) +_ROBOTPY_PYTHON_VERSION_TUPLE_FULL = (3, 14, 3) +_ROBOTPY_PYTHON_VERSION_TUPLE = _ROBOTPY_PYTHON_VERSION_TUPLE_FULL[:2] _ROBOTPY_PYTHON_VERSION_NUM = "".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE)) _ROBOTPY_PYTHON_VERSION = f"python{_ROBOTPY_PYTHON_VERSION_NUM}" diff --git a/robotpy_installer/pypackages.py b/robotpy_installer/pypackages.py index 3fefa0f..a54b9c7 100644 --- a/robotpy_installer/pypackages.py +++ b/robotpy_installer/pypackages.py @@ -250,14 +250,22 @@ def robot_env() -> Env: """ For use with ``packaging.marker.Marker.evaluate`` """ + from .installer import ( + _ROBOTPY_PYTHON_VERSION_TUPLE, + _ROBOTPY_PYTHON_VERSION_TUPLE_FULL, + ) + + python_version = ".".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE)) + python_full_version = ".".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE_FULL)) + return { "implementation_name": "cpython", - "implementation_version": "3.13.5", + "implementation_version": python_full_version, "os_name": "posix", "platform_machine": "systemcore", "platform_python_implementation": "CPython", "platform_system": "Linux", - "python_full_version": "3.13.0", - "python_version": "3.13", + "python_full_version": python_full_version, + "python_version": python_version, "sys_platform": "linux", } diff --git a/tests/test_pypackages.py b/tests/test_pypackages.py new file mode 100644 index 0000000..e92c9b8 --- /dev/null +++ b/tests/test_pypackages.py @@ -0,0 +1,37 @@ +from robotpy_installer import _pipstub +from robotpy_installer.installer import ( + _ROBOTPY_MANYLINUX_MAX, + _ROBOTPY_MANYLINUX_MIN, + _ROBOTPY_PYTHON_PLATFORM, + _ROBOTPY_PYTHON_VERSION_TUPLE, + _ROBOTPY_PYTHON_VERSION_TUPLE_FULL, + _PYTHON_PKG, +) +from robotpy_installer.pypackages import robot_env + + +def test_robot_env_matches_robotpy_python_version_tuple(): + robotpy_python_version = ".".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE)) + robotpy_python_full_version = ".".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE_FULL)) + + env = robot_env() + + assert env["python_version"] == robotpy_python_version + assert env["python_full_version"] == robotpy_python_full_version + assert env["implementation_version"] == robotpy_python_full_version + + +def test_python_pkg_uses_robotpy_python_full_version(): + robotpy_python_full_version = ".".join(map(str, _ROBOTPY_PYTHON_VERSION_TUPLE_FULL)) + + assert f"/cpython-{robotpy_python_full_version}+" in _PYTHON_PKG + + +def test_pipstub_matches_installer_robot_python_constants(): + assert _pipstub._ROBOTPY_PYTHON_PLATFORM == _ROBOTPY_PYTHON_PLATFORM + assert ( + _pipstub._ROBOTPY_PYTHON_VERSION_TUPLE_FULL + == _ROBOTPY_PYTHON_VERSION_TUPLE_FULL + ) + assert _pipstub._ROBOTPY_MANYLINUX_MIN == _ROBOTPY_MANYLINUX_MIN + assert _pipstub._ROBOTPY_MANYLINUX_MAX == _ROBOTPY_MANYLINUX_MAX