Skip to content

Commit d6e233c

Browse files
authored
check the ros2 prefix to fix humble packages (#197)
1 parent 482fba3 commit d6e233c

6 files changed

Lines changed: 148 additions & 7 deletions

File tree

‎.github/workflows/checks.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
persist-credentials: false
1616
- uses: prefix-dev/setup-pixi@d3f436a425481402e6a95a1d1fc10331c708cd9e # v0.10.2
1717
- run: pixi run lint
18+
- run: pixi run test
1819
- run: pixi run build-docs
1920

2021
dependabot:

‎.gitignore‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ RoboStack Website/
55
.pixi
66
*.egg-info
77

8+
# Python artifacts
9+
__pycache__/
10+
*.py[cod]
11+
*.pyo
12+
*.pyd
13+
*.pycache
14+
*.pytest_cache
15+
*.mypy_cache
16+
*.coverage
17+
coverage.xml
18+
htmlcov/
19+
820
# astro
921
node_modules
1022
dist

‎pixi.lock‎

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pixi.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ anaconda-client = ">=1.14.1,<2"
8585
pyyaml = ">=6,<7"
8686
py-rattler = ">=0.25,<0.26"
8787
niquests = ">=3.21.0,<4"
88+
pytest = ">=9.1.1,<10"
8889

8990
[feature.scripts.tasks]
91+
test = {
92+
cmd = "pytest scripts",
93+
description = "Run the Python regression tests",
94+
}
9095
check-dependabot-merge = {
9196
cmd = "python scripts/check_dependabot_merge.py",
9297
description = "Check whether every Dependabot update qualifies for auto-merge",

‎scripts/copy-to-distro-specific-channel.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44

55
import niquests
6+
from rattler import MatchSpec
67
from urllib3.util.retry import Retry
78

89
# Configuration
@@ -88,6 +89,29 @@ def get_timestamp_with_workaround_for_timestamp_in_seconds_instead_of_millisecon
8889
return timestamp
8990

9091

92+
def belongs_to_distro(pkg_data: dict, distro: str) -> bool:
93+
"""Identify renamed ROS packages by their distro-specific mutex build pin.
94+
95+
A version-only mutex pin is not enough: different distros can publish the
96+
same mutex version. Require the literal distro name in the build selector.
97+
"""
98+
name = pkg_data["name"]
99+
if name.startswith(f"ros-{distro}-"):
100+
return True
101+
if name in ("ros-distro-mutex", "ros2-distro-mutex"):
102+
return pkg_data["build"].split("_", 1)[0] == distro
103+
if not name.startswith("ros2-"):
104+
return False
105+
106+
for dependency in pkg_data.get("depends", []):
107+
if dependency.split(" ", 1)[0] != "ros2-distro-mutex":
108+
continue
109+
build = MatchSpec(dependency).build
110+
if build and build.split("_", 1)[0] == distro:
111+
return True
112+
return False
113+
114+
91115
def main() -> None:
92116
# Parse command-line arguments
93117
parser = argparse.ArgumentParser(
@@ -135,16 +159,10 @@ def main() -> None:
135159

136160
# Filter packages that belong to the given distro
137161
# and are newer then the specified cutoff date
138-
prefix = "ros-" + distro
139162
filtered_packages = {
140163
pkg_name: pkg_data
141164
for pkg_name, pkg_data in source_packages.items()
142-
# This should cover both packages that start with 'ros-<distro>'
143-
# '(ros|ros2)-<distro>-mutex' packages whose build string contains <distro>
144-
if (
145-
pkg_name.startswith(prefix)
146-
or (pkg_data["name"].endswith("distro-mutex") and distro in pkg_data["build"])
147-
)
165+
if belongs_to_distro(pkg_data, distro)
148166
and (
149167
get_timestamp_with_workaround_for_timestamp_in_seconds_instead_of_milliseconds(
150168
pkg_data
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import runpy
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
promotion = runpy.run_path(str(Path(__file__).with_name("copy-to-distro-specific-channel.py")))
7+
belongs_to_distro = promotion["belongs_to_distro"]
8+
9+
10+
@pytest.mark.parametrize(
11+
("dependencies", "expected"),
12+
[
13+
(["ros2-distro-mutex 0.10.* humble_*"], True),
14+
(
15+
[
16+
"ros2-distro-mutex >=0.10.0,<0.11.0a0",
17+
"ros2-distro-mutex 0.10.* humble_*",
18+
],
19+
True,
20+
),
21+
(["ros2-distro-mutex 0.10.* jazzy_*"], False),
22+
(["ros2-distro-mutex >=0.10.0,<0.11.0a0"], False),
23+
(["ros2-distro-mutex 0.10.* *"], False),
24+
(["ros2-distro-mutex 0.10.* humble-other_*"], False),
25+
(["ros2-rcl 16.*"], False),
26+
([], False),
27+
],
28+
)
29+
def test_renamed_package_requires_distro_build_pin(dependencies: list[str], expected: bool) -> None:
30+
artifact = {"name": "ros2-rclcpp", "depends": dependencies}
31+
assert belongs_to_distro(artifact, "humble") is expected
32+
33+
34+
def test_legacy_packages_and_shims_remain_distro_specific() -> None:
35+
shim = {"name": "ros-humble-rclcpp", "depends": ["ros2-rclcpp ==16.0.19"]}
36+
assert belongs_to_distro(shim, "humble")
37+
assert not belongs_to_distro(shim, "jazzy")
38+
assert belongs_to_distro({"name": "ros-noetic-roscpp"}, "noetic")
39+
assert not belongs_to_distro({"name": "ros-humble-other-rclcpp"}, "hum")
40+
41+
42+
@pytest.mark.parametrize(
43+
("name", "build", "distro", "expected"),
44+
[
45+
("ros2-distro-mutex", "humble_20", "humble", True),
46+
("ros2-distro-mutex", "humble", "humble", True),
47+
("ros2-distro-mutex", "jazzy_20", "humble", False),
48+
("ros2-distro-mutex", "not-humble_20", "humble", False),
49+
("ros-distro-mutex", "noetic_1", "noetic", True),
50+
],
51+
)
52+
def test_mutex_build_identifies_its_distro(
53+
name: str, build: str, distro: str, expected: bool
54+
) -> None:
55+
assert belongs_to_distro({"name": name, "build": build}, distro) is expected

0 commit comments

Comments
 (0)