Skip to content
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
41 changes: 25 additions & 16 deletions robotpy_installer/_pipstub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
3 changes: 2 additions & 1 deletion robotpy_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
14 changes: 11 additions & 3 deletions robotpy_installer/pypackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
37 changes: 37 additions & 0 deletions tests/test_pypackages.py
Original file line number Diff line number Diff line change
@@ -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
Loading