Skip to content

3di | Related packages (backport #7240) - #7384

Merged
ahcorde merged 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-7240
Nov 2, 2026
Merged

ahcorde merged 1 commit into
lyricalfrom
mergify/bp/lyrical/pr-7240

Conversation

@mergify

@mergify mergify Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

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's area from .. meta:: (from the Enhance metadata work #6981) against <area> exports in each package's package.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.js fills it in the browser on page load. The idea was that it would also fetch the {distro}-cache.yaml.gz live 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 html downloads 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

  • Uses the page's primary (first) area value from .. meta::, or :area: on the directive if you want to override it.
  • A package is listed when that value appears anywhere in its <area> export. So a page tagged nodes, framework doesn't pull in every package that only shares the broader framework parent.
  • area is 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> in package.xml. Unknown exports are ignored by the rest of the ROS toolchain (REP 149), so this is safe to add:

<export>
  <build_type>ament_cmake</build_type>
  <area>nodes, framework</area>
  <related_scope>core</related_scope>
</export>

<area> is comma-separated, most specific first, and decides which pages the package shows up on. <related_scope> is optional and is either core or federation. Missing or unrecognised values are treated as federation, 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 an h3 and 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 h4 headings, sorted alphabetically, with each package's <description> after its name:

  • Core ROS packages for <related_scope>core
  • Community packages for federation, or when related_scope is missing

In 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 packages and Show 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 at https://repo.ros2.org/rosdistro_cache/. Its release_package_xmls key maps package names to the full text of each released package.xml.

The script tries three sources in order and uses the first one that works:

  1. Same-origin proxy at /api/rosdistro-cache/{distro}-cache.yaml.gz. Live data. The path comes from ros_related_packages_proxy_url in conf.py and can be overridden with the ROS_RELATED_PACKAGES_PROXY_URL environment 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 with tools/serve_docs_with_proxy.py.
  2. Bundled copy under _static/rosdistro_cache/, downloaded during make html and 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.
  3. Direct fetch from 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 area and 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.gz on the docs origin is served from https://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 in conf.py or 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. An Access-Control-Allow-Origin header for the docs origin on repo.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:

  • Pages have area in .. meta:: (Enhance metadata PR 3di | Enhance metadata #6981) and .. ros-related-packages:: where needed.
  • Packages declare <area> in package.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 area to a page, add .. ros-related-packages:: (and optionally Related 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, run python tools/serve_docs_with_proxy.py after the build instead of a plain static server.

Changes

  • Add plugins/ros_related_packages.py: the directive, the ros_related_packages_proxy_url config value, and the builder-inited hook that downloads the cache for HTML builds. A failed download warns and doesn't break the build.
  • Add 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.
  • Add vendored source/_static/vendor/pako.min.js and js-yaml.min.js, so there's no CDN dependency on page load.
  • Add plugins/ros_related_packages.md (author guide and developer notes, including the onload options above).
  • Add tools/serve_docs_with_proxy.py and tools/rosdistro_cache_proxy.py for preivewing the proxy path locally. Neither is used by the Sphinx build.
  • Update 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).

* 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)
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

HTML artifacts: https://github.com/ros2/ros2_documentation/actions/runs/41262726029/artifacts/13066135630.

To view the resulting site:

  1. Click on the above link to download the artifacts archive
  2. Extract it
  3. Open html-artifacts-7384/index.html in your favorite browser

@ahcorde
ahcorde merged commit f93c6bf into lyrical Nov 2, 2026
6 checks passed
@ahcorde
ahcorde deleted the mergify/bp/lyrical/pr-7240 branch November 2, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants