2525would 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+
2836The 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 )
102126class 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+
109170def 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]:
264325def 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
307387def 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" ,
0 commit comments