feat: integrate sphinx-mounts for external source bundles#554
Open
ubmarco wants to merge 1 commit into
Open
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //src:license-checkStatus: Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
Wires the sphinx-mounts extension into the docs() Bazel macro so RST
or Markdown content that lives outside docs/ (generated under bazel-bin,
or in-repo next to its source code) can be surfaced in the Sphinx build
without copying or symlinking. Files stay where they live and are
visible to Sphinx via absolute paths registered through TOML.
Why the TOML angle matters: ubCode (and any non-Python tool) reads
ubproject.toml to discover the project. With mount entries in the host
TOML and a sanitized ubproject.toml at each in-repo bundle's source root,
the IDE resolves both the host and the bundle without ever invoking
Sphinx -- giving as-you-type validation that a Sphinx-mediated workflow
cannot match. This is an alternative to the materialize-a-tree approach;
both can coexist, but the mount surface is lighter-weight and IDE-friendly.
Surface added
-------------
* mount(label, mount_at, attach_to=None, entry_doc="index", src_root=None)
helper in docs.bzl. Mount entries pass through env MOUNTS as JSON,
symmetric to data = [...] / external_needs_source.
* files_to_dir Starlark rule that materialises a glob of files into a
single declared-directory output under bazel-bin (the shape that
sphinx-mounts' dir mode walks).
* score_mounts Sphinx extension that:
- parses MOUNTS, resolves runfile paths,
- sets config.mounts in-memory for sphinx-mounts at build time,
- emits a [[mounts]] fragment with portable confdir-relative paths
pointing at the *real source location* (not the bazel-bin copy),
so IDE jump-to-definition lands on the file the author wrote,
- generates a sanitized per-bundle ubproject.toml at each in-repo
bundle's src_root for ubCode's directory-walk project lookup.
* New //:docs_html sandboxed HTML build target alongside //:needs_json.
* Comprehensive how-to at docs/how-to/mount_external_sources.rst.
Demo
----
* src/docs/ ships a small "Code Docs" bundle (index, overview,
requirements). Mounted under docs/internals/code_docs/ with
attach_to = "internals/index" so the host toctree auto-extends.
* stkh_req__docs__mounts (in the bundle) is referenced from the host
via :satisfies: on tool_req__docs_mount_traceability. The link uses
only stock relations from score_metamodel (tool_req's existing
optional_links permits satisfying stkh_req); no metamodel change
is needed to demonstrate cross-bundle traceability.
Ancillary fix
-------------
* score_sync_toml: flip needscfg_exclude_defaults to False. needs.types,
needs.links, needs.fields were being stripped from the generated
ubproject.toml because they happen to compare equal to sphinx-needs'
declared defaults; the result was a TOML with no type catalogue, so
IDE tooling could not resolve project directives like tool_req.
684d546 to
ced7e05
Compare
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.
Summary
Alternative POC for surfacing RST/Markdown content from outside
docs/(generated under
bazel-bin/, or in-repo next to its source) in theSphinx build without copying or symlinking. Wires the
sphinx-mountsextension intothe
docs()Bazel macro: files stay where they live; the IDE readsthe same
ubproject.tomlSphinx reads, so as-you-type validationworks without invoking Sphinx.
Demo: mounts
src/docs/atdocs/internals/code_docs/under thehost's "Internals" section. A cross-bundle
:satisfies:link from ahost
tool_reqto the bundle'sstkh_req__docs__mountsprovestraceability works across the mount boundary as a first-class
sphinx-needs relation — using only stock metamodel relations;
no
score_metamodel/metamodel.yamlchange is needed.What's included
mount()helper +mountsparameter ondocs()(docs.bzl).files_to_dirStarlark rule that turns a glob into a singledeclared-directory output under
bazel-bin/.score_mountsSphinx extension: parses MOUNTS, resolves runfilepaths, emits a
[[mounts]]TOML fragment with portableconfdir-relative paths pointing at the real source location
(not the bazel-bin copy), and generates a sanitized per-bundle
ubproject.tomlat each in-reposrc_rootso ubCode'sdirectory-walk lookup finds the project's type system from inside
the bundle.
//:docs_htmlalongside//:needs_json.docs/how-to/mount_external_sources.rst(rationale, comparison with materialise-a-tree approach, full
API reference, caveats).
src/docs/, mounted underdocs/internals/code_docs/.tool_req(
tool_req__docs_mount_traceabilityindocs/internals/requirements/requirements.rst) carries a:satisfies:link to the bundle-side stakeholder requirement(
stkh_req__docs__mountsinsrc/docs/requirements.rst).Test plan
bazel test //src/extensions/score_mounts:score_mounts_tests— 20 unit tests.bazel build //:needs_json— sandboxed needs.json build.bazel build //:docs_html— sandboxed HTML build.bazel run //:docs_check— regeneratesdocs/ubproject.tomlandsrc/docs/ubproject.toml; both contain the type catalogue.bazel run //:docs— hostindex.htmlshows "Code Docs" auto-extended into theinternals/indextoctree;_build/internals/code_docs/{index,overview,requirements}.htmlexist.tool_req__docs_mount_traceabilityindocs/:satisfies:stkh_req__docs__mountsin the mounted bundle without sphinx-needs warnings.Notes for reviewers
docs/how-to/mount_external_sources.rstexplains when to prefer mounts over a materialise-a-tree approach
(the two are not mutually exclusive).
docs/ubproject.tomlis gitignored (existing convention);src/docs/ubproject.tomlis added to.gitignorefor the samereason.
needs.types,needs.links, andneeds.fieldswere being stripped from the generatedubproject.tomlbecauseneedscfg_exclude_defaults = Truefiltered values matching sphinx-needs' declared defaults. Without
the type catalogue the TOML was effectively useless to IDEs (e.g.
ubCode could not resolve
tool_req). Flipped toFalseinscore_sync_toml/__init__.py. The generated file grows, but thevalues are now actually present where consumers expect them.
score_metamodel/metamodel.yamlisuntouched in this PR. The cross-bundle link uses
tool_req'sexisting
optional_links: satisfies: gd_req, stkh_req, feat_req, comp_reqdeclaration — by authoring the mount-featurerequirement as a
stkh_req(which has no link constraints), thehost's
tool_reqcan satisfy it via the stock relation.