Repository navigation
3di | Related packages (backport #7240) - #7384
Merged
Merged
Conversation
* Add related packages solution * Update to align with most recent requirements * Update related scope metadata values * Add readme * Align related packages meta key matching with docs conventions * Move cache source rationale out of code into the extension docs * Prefix package.xml exports with ros2_documentation Address Shane's feedback on ros2/rclcpp#3309 to have the names in export prefixed. (cherry picked from commit 191ddd4)
|
HTML artifacts: https://github.com/ros2/ros2_documentation/actions/runs/41262726029/artifacts/13066135630. To view the resulting site:
|
ahcorde
approved these changes
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a Sphinx extension with a
.. ros-related-packages::directive for listing the ROS packages that belong with a given docs page. Matching uses the page'sareafrom.. meta::(from the Enhance metadata work #6981) against<area>exports in each package'spackage.xml, taken from the rosdistro cache the build farm publishes.Unlike related articles (#7239), the lists aren't written into the HTML. The directive only emits a placeholder, and
related_packages.jsfills it in the browser on page load. The idea was that it would also fetch the{distro}-cache.yaml.gzlive at that point, so the package set stays current between docs builds without shipping thousands of package names in every page.Doing that needs a copy of the cache file the browser is allowed to read, and I don't know enough about how docs.ros.org is hosted to say exactly how you'd provide one. So what this PR does by default is on build:
make htmldownloads the cache into_static/, and the widget reads that same-origin copy when the user opens the page. The lists work, they're just only as fresh as the last docs build. The onload path is already wired up and configurable, and I've been running it locally behind a small proxy. Below is what I think you'd need on your end to turn it on, but it's a suggestion rather than something I can check against your setup.Matching
areavalue from.. meta::, or:area:on the directive if you want to override it.<area>export. So a page taggednodes, frameworkdoesn't pull in every package that only shares the broaderframeworkparent.areais required (meta or the option). Missing it fails the build. Packages with no<area>export are never listed.:max:optionally caps how many packages appear in each group.Package metadata
Matching needs two custom tags under
<export>inpackage.xml. Unknown exports are ignored by the rest of the ROS toolchain (REP 149), so this is safe to add:<area>is comma-separated, most specific first, and decides which pages the package shows up on.<related_scope>is optional and is eithercoreorfederation. Missing or unrecognised values are treated asfederation, which is the Community packages group.Nothing released carries these exports yet, so against the live cache the lists currently match nothing. This PR is the mechanism only, package adoption can come afterwards. I've opened ros2/rclcpp#3309 as a worked example of what a package needs to declare, and I'll be adding the same to the other core packages.
Output
If the author writes
Related packages:as a normal paragraph above the widget, page load turns that into anh3and strips the colon. If it's already a heading, or worded differently, or not there at all, nothing happens to it.Matching packages are split into two groups under
h4headings, sorted alphabetically, with each package's<description>after its name:<related_scope>corefederation, or whenrelated_scopeis missingIn case someone wanted to add an extra link manually, any list immediately before or after the directive is kept as hand-written. The script picks up the package name from the
/p/<name>/bit of the URL, or from the link text when that's a single word. If that package also matches by area, the plain bullet is dropped and the package is shown in the right group instead, with the description and heading. If it doesn't match, it stays where the author put it. Either way a package only appears once.Each group shows the first 7 packages, then a control that toggles between
Show N more packagesandShow fewer. If nothing matched and there's no hand-written list, the placeholder shows a plain status rather than an empty heading.Where the package data comes from
It all comes from one file,
{distro}-cache.yaml.gz, published by the build farm athttps://repo.ros2.org/rosdistro_cache/. Itsrelease_package_xmlskey maps package names to the full text of each releasedpackage.xml.The script tries three sources in order and uses the first one that works:
/api/rosdistro-cache/{distro}-cache.yaml.gz. Live data. The path comes fromros_related_packages_proxy_urlinconf.pyand can be overridden with theROS_RELATED_PACKAGES_PROXY_URLenvironment variable. Nothing serves this on docs.ros.org today, so the the request fails and the script moves on to the next one. Locally I serve it withtools/serve_docs_with_proxy.py._static/rosdistro_cache/, downloaded duringmake htmland gitignored so it never goes into the repository. Always same-origin, so this is what actually serves users today, and it's why the lists work without any hosting change. As fresh as the last docs build.https://repo.ros2.org/rosdistro_cache/{distro}-cache.yaml.gz. Live data, but browsers normally block reading another origin without CORS, so this one rarely works.Source 2 is the default in production and it's enough. Merge this, put
areaand the directive on pages, get packages to declare<area>, and the lists fill. The only thing missing is refreshing between docs builds.What I think you would need for onload data
This sits outside this repository, so the below is a suggestion, not something I can verify agains your infrastructure. Either option on its own is enough, and once one is in place nothing further changes in the docs.
Option A, a same-origin route on the docs host. A rewrite or reverse proxy so a request to
/api/rosdistro-cache/{distro}-cache.yaml.gzon the docs origin is served fromhttps://repo.ros2.org/rosdistro_cache/{distro}-cache.yaml.gz, passing the gzip body through unchanged so the browser can still inflate it. Source 1 then works. If a different path or host suits you better, that's a value change inconf.pyor the environment variable. Setting the variable to an empty string turns the attempt off and sticks to the build-time copy.Option B, CORS on
repo.ros2.org. AnAccess-Control-Allow-Originheader for the docs origin onrepo.ros2.org/rosdistro_cache/. Source 3 then works directly and the proxy can be dropped.Either way its worth putting a short cache lifetime in front of the file. It's a few hundred kilobytes and only changes when the build farm republishes, so caching for minutes rather than seconds keeps repeated page loads off
repo.ros2.org. Both local tools here cache for five minutes for that reason.I don't have a preference between A and B, and staying on the build-time copy is a fine answer too. Happy to change it whichever way you prefer. There's more detail, including the placeholder markup and the local preview commands, in
plugins/ros_related_packages.md.Dependencies
Mechanism only. No articles change in this PR. Useful lists show up once:
areain.. meta::(Enhance metadata PR 3di | Enhance metadata #6981) and.. ros-related-packages::where needed.<area>inpackage.xml, and optionally<related_scope>. See ros2/rclcpp#3309 for what that looks like.Until packages adopt the exports, groups stay empty or show "no packages matched". That's expected and safe to merge. The hosting work above is optional and only affects freshness, not whether the feature works.
Testing
Add
areato a page, add.. ros-related-packages::(and optionallyRelated packages:above it) and build the output. The widget should load from the bundled copy. Lists stay empty until packages have<area>, so use a local fixture if you want to see poulated groups. To try the same-origin path, runpython tools/serve_docs_with_proxy.pyafter the build instead of a plain static server.Changes
plugins/ros_related_packages.py: the directive, theros_related_packages_proxy_urlconfig value, and thebuilder-initedhook that downloads the cache for HTML builds. A failed download warns and doesn't break the build.source/_static/related_packages.js: fetches and filters the cache (gzip via pako, YAML via js-yaml), splits Core from Community, absorbs hand-written links, promotes the intro, and adds the expand control.source/_static/vendor/pako.min.jsandjs-yaml.min.js, so there's no CDN dependency on page load.plugins/ros_related_packages.md(author guide and developer notes, including the onload options above).tools/serve_docs_with_proxy.pyandtools/rosdistro_cache_proxy.pyfor preivewing the proxy path locally. Neither is used by the Sphinx build.source/_static/custom.css,conf.py, and.gitignore(the downloaded cache is ignored).Did you use Generative AI?
Yes – Cursor IDE, using models Composer 2.5, Gemini Pro 3.1, Flash 3.6, and Anthropic Sonnet 5 / Opus 5.
Additional Information
Issue: #6991
This is an automatic backport of pull request #7240 done by [Mergify](https://mergify.com).