Skip to content

Commit 58ce947

Browse files
authored
Pick the package name prefix per mutex, not per distro (#168)
Rolling publishes `ros2-<pkg>` for mutex 0.19 and published `ros-rolling-<pkg>` for everything before it, so a page-wide prefix left every older mutex at 0% available. Packages are now keyed by their bare name and the dataset records the prefix each mutex generation uses, which the table puts in front of every name it shows. The `ros-rolling-<pkg>` compatibility packages are dropped: they only pin the `ros2-<pkg>` of the same version and constrain no mutex, so counting them would advertise today's version on every older mutex too.
1 parent a98a876 commit 58ce947

4 files changed

Lines changed: 148 additions & 52 deletions

File tree

‎scripts/compare_pkg_completeness.py‎

Lines changed: 112 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
would work today, but the specs appear in two forms (`0.9.* humble_*` and
2626
`>=0.9.0,<0.10.0a0`) and nothing stops a third from showing up.
2727
28+
How a package is spelled is relative to a mutex as well. Rolling published
29+
`ros-rolling-<pkg>` up to mutex 0.18 and `ros2-<pkg>` from 0.19 on, so packages are
30+
keyed by their bare name and the document records the prefix each mutex generation
31+
publishes under. The `ros-rolling-<pkg>` packages that came along with the switch are
32+
compatibility shims that do nothing but pin the `ros2-<pkg>` of the same version;
33+
they constrain no mutex of their own and are dropped, so that the current version
34+
does not show up as available on every older mutex too.
35+
2836
The JSON is positional to keep it small; `PackageTable.svelte` unpacks it via the
2937
`fields` list in the document head, so the two only have to agree on the names.
3038
@@ -98,6 +106,22 @@ class Slot:
98106
version: str = ""
99107

100108

109+
@dataclass
110+
class Builds:
111+
"""Everything the channel has, folded down to what the page needs.
112+
113+
`slots` is keyed by the bare package name, because a package can be published
114+
under more than one prefix: on Rolling, `ros2-tf2-ros` and `ros-rolling-tf2-ros`
115+
are the same package built for different mutex generations. `prefixes` says which
116+
spelling each generation uses, and `newest` holds the newest build timestamp per
117+
package, which drives the "recently built" sort.
118+
"""
119+
120+
slots: dict[str, dict[str, Slot]]
121+
newest: dict[str, int]
122+
prefixes: dict[str, str]
123+
124+
101125
@dataclass(frozen=True)
102126
class IndexEntry:
103127
"""A package as `rosdistro` describes it, before we look at any channel."""
@@ -106,6 +130,43 @@ class IndexEntry:
106130
source: str
107131

108132

133+
def package_prefixes(distro: str) -> tuple[str, ...]:
134+
"""The conda name prefixes a distro's packages can carry, preferred first.
135+
136+
Rolling moved from `ros-rolling-` to `ros2-` partway through, so both spellings
137+
are live on its channel. The other distros only ever used their own prefix, and
138+
the unused candidate simply never wins an election in `collect_builds`.
139+
"""
140+
return (f"ros-{distro}", "ros2")
141+
142+
143+
def split_name(name: str, prefixes: tuple[str, ...]) -> tuple[str, str] | None:
144+
"""`ros2-tf2-ros` -> `("ros2", "tf2-ros")`, or None for a foreign name.
145+
146+
Channels carry the odd artifact from another distro (jazzy has two `ros-humble-*`
147+
ones), which belongs on no page here.
148+
"""
149+
for prefix in prefixes:
150+
if name.startswith(f"{prefix}-"):
151+
return prefix, name[len(prefix) + 1 :]
152+
return None
153+
154+
155+
def is_shim(artifact: Artifact, name: str, prefixes: tuple[str, ...]) -> bool:
156+
"""Whether the artifact is a compatibility package for its own other spelling.
157+
158+
Rolling's `ros-rolling-<pkg>` shims pin `ros2-<pkg>` and hold nothing else. They
159+
depend on no mutex, so counting them as builds would advertise today's version on
160+
every older mutex as well.
161+
"""
162+
for dependency in artifact.get("depends", []):
163+
depended = dependency.split(" ")[0]
164+
split = split_name(depended, prefixes)
165+
if depended != artifact["name"] and split and split[1] == name:
166+
return True
167+
return False
168+
169+
109170
def fetch_yaml(url: str) -> Any: # noqa: ANN401 - shape differs per rosdistro file
110171
"""GET and parse a YAML document, raising on a bad status."""
111172
response = session.get(url)
@@ -264,25 +325,34 @@ def resolve(spec: str) -> set[str]:
264325
def collect_builds(
265326
repos: dict[str, list[Artifact]],
266327
mutexes: list[str],
328+
prefixes: tuple[str, ...],
267329
resolve: Callable[[str], set[str]],
268-
) -> tuple[dict[str, dict[str, Slot]], dict[str, int]]:
269-
"""Fold every artifact into `{conda name: {mutex version: Slot}}`.
330+
) -> Builds:
331+
"""Fold every artifact into `{package: {mutex version: Slot}}`.
270332
271-
Also returns the newest build timestamp per package, which drives the "recently
272-
built" sort. An artifact with no mutex dependency works with any of them.
333+
An artifact with no mutex dependency works with any of them. Which prefix a mutex
334+
generation publishes under is elected from the artifacts that do name it: the
335+
spelling that most of them use, and the distro's own prefix for a generation that
336+
has none left.
273337
"""
274-
builds: dict[str, dict[str, Slot]] = {}
275-
newest_build: dict[str, int] = {}
338+
slots: dict[str, dict[str, Slot]] = {}
339+
newest: dict[str, int] = {}
340+
votes: dict[str, dict[str, int]] = {}
276341
unconstrained = 0
277342

278343
for bit, platform in enumerate(PLATFORMS):
279344
for artifact in repos[platform]:
280-
name = artifact["name"]
281-
if not (name.startswith("ros-") or name.startswith("ros2-")) or name in MUTEX_NAMES:
345+
if artifact["name"] in MUTEX_NAMES:
346+
continue
347+
split = split_name(artifact["name"], prefixes)
348+
if not split:
349+
continue
350+
prefix, name = split
351+
if is_shim(artifact, name, prefixes):
282352
continue
283353

284-
newest_build[name] = max(
285-
newest_build.get(name, 0), normalize_timestamp(artifact.get("timestamp") or 0)
354+
newest[name] = max(
355+
newest.get(name, 0), normalize_timestamp(artifact.get("timestamp") or 0)
286356
)
287357

288358
specs = [d for d in artifact.get("depends", []) if d.split(" ")[0] in MUTEX_NAMES]
@@ -295,13 +365,23 @@ def collect_builds(
295365
unconstrained += 1
296366

297367
for version in allowed:
298-
slot = builds.setdefault(name, {}).setdefault(version, Slot())
368+
if specs:
369+
ballot = votes.setdefault(version, {})
370+
ballot[prefix] = ballot.get(prefix, 0) + 1
371+
slot = slots.setdefault(name, {}).setdefault(version, Slot())
299372
slot.mask |= 1 << bit
300373
if not slot.version or version_key(artifact["version"]) > version_key(slot.version):
301374
slot.version = artifact["version"]
302375

303376
print(f" artifacts with no mutex constraint: {unconstrained}", file=sys.stderr)
304-
return builds, newest_build
377+
return Builds(
378+
slots=slots,
379+
newest=newest,
380+
prefixes={
381+
version: min(ballot, key=lambda p: (-ballot[p], prefixes.index(p)))
382+
for version, ballot in votes.items()
383+
},
384+
)
305385

306386

307387
def build(distro: str, channel: str) -> dict[str, Any]:
@@ -319,7 +399,12 @@ def build(distro: str, channel: str) -> dict[str, Any]:
319399
mutexes = sorted(mutex_records, key=version_key, reverse=True)[:MUTEX_LIMIT]
320400
print(f" mutex: {mutex_package} {mutexes}", file=sys.stderr)
321401

322-
builds, newest_build = collect_builds(repos, mutexes, mutex_matcher(mutex_records))
402+
prefixes = package_prefixes(distro)
403+
builds = collect_builds(repos, mutexes, prefixes, mutex_matcher(mutex_records))
404+
# Aligned with "mutexes": the prefix that generation's packages are published
405+
# under, which is what the page puts in front of every name it shows.
406+
naming = [builds.prefixes.get(version, prefixes[0]) for version in mutexes]
407+
print(f" naming: {dict(zip(mutexes, naming, strict=True))}", file=sys.stderr)
323408

324409
# Hundreds of packages come out of the same repository, so the URLs are interned
325410
# and each package stores an index into this list.
@@ -332,10 +417,8 @@ def slots(per_mutex: dict[str, Slot]) -> list[Any]:
332417
return [[per_mutex[v].mask, per_mutex[v].version] if v in per_mutex else 0 for v in mutexes]
333418

334419
packages: list[list[Any]] = []
335-
package_prefix = "ros2" if distro == "rolling" else f"ros-{distro}"
336420
for name in sorted(index):
337-
conda_name = f"{package_prefix}-{name.replace('_', '-')}"
338-
per_mutex = builds.get(conda_name, {})
421+
package = name.replace("_", "-") # conda spelling, no distro prefix
339422
entry = index[name]
340423

341424
if entry.source and entry.source not in repo_index:
@@ -344,37 +427,29 @@ def slots(per_mutex: dict[str, Slot]) -> list[Any]:
344427

345428
packages.append(
346429
[
347-
name.replace("_", "-"), # conda spelling, distro prefix stripped
348-
conda_name,
430+
package,
349431
metadata.get(name, ""),
350432
entry.version, # as released into the ROS index
351-
newest_build.get(conda_name, 0) // 1000, # newest build, seconds
433+
builds.newest.get(package, 0) // 1000, # newest build, seconds
352434
repo_index.get(entry.source, -1), # index into "repos"
353435
1, # released into the ROS index
354-
slots(per_mutex),
436+
slots(builds.slots.get(package, {})),
355437
]
356438
)
357439

358440
# Packages on the channel that rosdistro has never released: no description,
359-
# index version or source repository, but installable all the same. Rolling's
360-
# ros-rolling-* names are skipped here: they are empty shims pinning the
361-
# ros2-* package of the same version, so a row of their own would duplicate
362-
# every package on the page.
363-
prefix = f"{package_prefix}-"
364-
released = {f"{package_prefix}-{name.replace('_', '-')}" for name in index}
365-
for conda_name in sorted(set(builds) - released):
366-
if not conda_name.startswith(prefix):
367-
continue
441+
# index version or source repository, but installable all the same.
442+
released = {name.replace("_", "-") for name in index}
443+
for package in sorted(set(builds.slots) - released):
368444
packages.append(
369445
[
370-
conda_name.removeprefix(prefix),
371-
conda_name,
446+
package,
372447
"",
373448
"",
374-
newest_build.get(conda_name, 0) // 1000,
449+
builds.newest.get(package, 0) // 1000,
375450
-1,
376451
0,
377-
slots(builds[conda_name]),
452+
slots(builds.slots[package]),
378453
]
379454
)
380455
packages.sort(key=lambda package: package[0])
@@ -385,9 +460,9 @@ def slots(per_mutex: dict[str, Slot]) -> list[Any]:
385460
"platforms": PLATFORMS,
386461
"mutexPackage": mutex_package,
387462
"mutexes": mutexes,
463+
"prefixes": naming,
388464
"fields": [
389465
"name",
390-
"condaName",
391466
"desc",
392467
"indexVersion",
393468
"updated",
@@ -429,8 +504,9 @@ def refresh(distro: str, channel: str) -> None:
429504

430505
total = len(document["packages"])
431506
newest = document["mutexes"][0] if document["mutexes"] else None
432-
on_newest = sum(1 for p in document["packages"] if p[7] and p[7][0])
433-
ever = sum(1 for p in document["packages"] if any(p[7]))
507+
at = document["fields"].index("builds")
508+
on_newest = sum(1 for p in document["packages"] if p[at] and p[at][0])
509+
ever = sum(1 for p in document["packages"] if any(p[at]))
434510
print(
435511
f" -> {path}: {total} packages, {ever} built at some point, "
436512
f"{on_newest} on mutex {newest}, {path.stat().st_size / 1e6:.2f} MB",

‎src/components/package-table/PackageTable.svelte‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
baseVersion,
2323
deriveMutexRows,
2424
matchesFilter,
25+
mutexPrefixes,
2526
relevanceTier,
2627
SORTERS,
2728
unpackRows,
@@ -94,6 +95,10 @@
9495
const mutexPackage = $derived(doc?.mutexPackage ?? "");
9596
const mutexes = $derived(doc?.mutexes ?? []);
9697
const currentMutex = $derived(mutexes[mutex] ?? "");
98+
/* Rolling renamed its packages from ros-rolling-* to ros2-* partway
99+
* through, so the prefix every name on the page carries comes from the
100+
* selected mutex rather than from the distro. */
101+
const prefix = $derived((doc ? (mutexPrefixes(doc)[mutex] ?? "") : "") + "-");
97102
98103
const all: Row[] = $derived(doc ? unpackRows(doc) : []);
99104
@@ -473,10 +478,7 @@
473478
</tr>
474479
{/if}
475480
{#each slice as row, i (row.name)}
476-
{@const conda = row.condaName}
477-
<!-- Every row on a page carries the same prefix, so it is split
478-
back off the conda name for the muted/hidden treatment. -->
479-
{@const prefix = conda.slice(0, conda.length - row.name.length)}
481+
{@const conda = prefix + row.name}
480482
<!-- The ROS index spells package names with underscores; conda
481483
uses hyphens. -->
482484
{@const rosName = row.name.replace(/-/g, "_")}

‎src/components/package-table/data.ts‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,35 @@ export interface Doc {
2121
platforms: string[];
2222
mutexPackage: string;
2323
mutexes: string[];
24+
/** Aligned with `mutexes`: the conda name prefix that mutex generation
25+
* publishes under. Missing on the committed end-of-life snapshots. */
26+
prefixes?: string[];
2427
fields: string[];
2528
repos: string[];
2629
packages: PackageEntry[];
2730
}
2831

32+
/**
33+
* The conda name prefix for each mutex, aligned with `doc.mutexes`.
34+
*
35+
* A package is spelled differently on different mutexes: rolling publishes
36+
* `ros2-rclcpp` for 0.19 and published `ros-rolling-rclcpp` for everything
37+
* before it. The foxy and galactic snapshots predate the field and are
38+
* `ros-<distro>-` throughout.
39+
*/
40+
export function mutexPrefixes(doc: Doc): string[] {
41+
return doc.mutexes.map((_, i) => doc.prefixes?.[i] ?? `ros-${doc.distro}`);
42+
}
43+
2944
export interface Upgrade {
3045
version: string;
3146
mutex: string;
3247
}
3348

3449
export interface Row {
35-
/** The ROS package name in conda's hyphen spelling, with the distro's
50+
/** The ROS package name in conda's hyphen spelling, with the channel's
3651
* package prefix stripped. */
3752
name: string;
38-
/** The name the package is published under on the channel, prefix and all:
39-
* `ros2-desktop` on rolling, `ros-jazzy-desktop` everywhere else. */
40-
condaName: string;
4153
desc: string;
4254
indexVersion: string;
4355
updated: number;
@@ -94,25 +106,25 @@ export function compareVersions(a: string, b: string): number {
94106
export function unpackRows(doc: Doc): Row[] {
95107
const at: Record<string, number> = {};
96108
doc.fields.forEach((field, i) => (at[field] = i));
109+
// Someone searching for a package is as likely to type the name they would
110+
// install as the bare one, so every spelling the channel has used goes into
111+
// the haystack.
112+
const spellings = [...new Set(mutexPrefixes(doc))];
97113
return doc.packages.map((pkg) => {
98114
const name = pkg[at.name] as string;
99-
// The committed foxy and galactic snapshots predate condaName. They are
100-
// ROS 1-era ros-<distro>-<name> data, so reconstruct that spelling rather
101-
// than applying today's rolling ros2-* convention to them.
102-
const condaName =
103-
((pkg[at.condaName] ?? "") as string) || `ros-${doc.distro}-${name}`;
104115
const desc = (pkg[at.desc] ?? "") as string;
105116
const repo = pkg[at.repo] as number;
106117
return {
107118
name,
108-
condaName,
109119
desc,
110120
indexVersion: (pkg[at.indexVersion] ?? "") as string,
111121
updated: (pkg[at.updated] ?? 0) as number,
112122
repo: repo >= 0 ? (doc.repos[repo] ?? "") : "",
113123
indexed: at.indexed === undefined || Boolean(pkg[at.indexed]),
114124
builds: pkg[at.builds] as BuildSlot[], // aligned with doc.mutexes
115-
haystack: (name + " " + condaName + " " + desc).toLowerCase(),
125+
haystack: [name, ...spellings.map((p) => `${p}-${name}`), desc]
126+
.join(" ")
127+
.toLowerCase(),
116128
};
117129
});
118130
}

‎src/data/distros.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ export function browseUrl(distro: Distro): string {
9898
export function title(distro: Distro): string {
9999
return distro.name.charAt(0).toUpperCase() + distro.name.slice(1);
100100
}
101-
/** The conda package prefix used for the distro's primary packages. */
101+
/**
102+
* The conda package prefix used for the distro's primary packages.
103+
*
104+
* Rolling switched from `ros-rolling-` to `ros2-` with mutex 0.19. The package
105+
* table reads the prefix per mutex out of its dataset; this is the build-time
106+
* answer for the current one, which is what an install snippet wants.
107+
*/
102108
export function packagePrefix(distro: Distro): string {
103109
return distro.name === "rolling" ? "ros2" : `ros-${distro.name}`;
104110
}

0 commit comments

Comments
 (0)