Add SysML / Gaphor diagrams under sphinx-needs items (prototype)#50
Add SysML / Gaphor diagrams under sphinx-needs items (prototype)#50ubmarco wants to merge 2 commits into
Conversation
Demonstrates that ``.. diagram::`` from gaphor.extensions.sphinx works
the same way as ``.. uml::`` does today: it can be embedded directly
inside a sphinx-needs ``arch::`` item and renders to SVG/PDF on every
build.
Wires up:
- gaphor>=3.3.2 as a dependency and ``gaphor.extensions.sphinx`` in
``conf.py`` with a ``gaphor_models`` mapping.
- Two model files under ``docs/automotive-adas/sysml/``:
``adas-tsr-bdd.gaphor`` (regenerated by ``author_adas_bdd.py``) and
Gaphor's stock ``sysml-car.gaphor`` example.
- A diagram embedded under ARCH_007 (Traffic Sign Recognition) next to
the existing PlantUML view.
- A new ``sysml/index.rst`` page that explains the integration, the
authoring workflow (GUI vs Python API) and why dropping in raw SysML
1.5 XMI is not viable today (Gaphor removed XMI export in 3.1.0; the
``.gaphor`` schema differs from XMI).
- Read-the-Docs apt packages required by PyGObject + Cairo.
- ``matplotlib.use("Agg")`` early in ``conf.py`` to keep matplotlib off
the GTK4 backend that PyGObject would otherwise default to (the cause
of a build hang at "writing output... [4%]" on headless hosts).
Notes for review:
- Gaphor implements SysML 1.6, the minor revision of 1.5 that retains
the same core constructs (Block, Property, Port, Connector,
Requirement); for a "SysML 1.5" customer showcase this is the right
fit.
- ``adas-tsr-bdd.gaphor`` is text/XML and tracked as code; rerun
``uv run python docs/automotive-adas/sysml/author_adas_bdd.py`` to
regenerate after structural changes.
Addresses two review issues:
1. Cairo / PyGObject build failure on Read-the-Docs. Gaphor's Sphinx
extension needs Cairo + GTK girepository at build time, which
require a C toolchain. They are now decoupled from the doc build:
- ``gaphor`` moves to a ``[render]`` optional extra; the doc build
only sees the ordinary Sphinx + sphinx-needs stack.
- ``gaphor.extensions.sphinx`` is dropped from ``conf.py``; the
``gaphor_models`` mapping is removed.
- The Gaphor-related ``apt_packages`` are removed from
``.readthedocs.yaml``.
- SysML diagrams are now ordinary committed SVGs embedded with
``.. figure::``.
2. BDD layout looked broken. The previous Python authoring placed
``PropertyItem`` parts at hard-coded offsets that overlapped the
parent block's name and ``«block»`` stereotype. The script now
sets ``BlockItem.show_parts = 1`` so Gaphor renders parts inside
the parent's "parts" compartment, and arranges the parent + three
sub-blocks on a clean two-row grid. The committed
``adas-tsr-bdd__tsr-block-definition.svg`` reflects the new layout.
New rendering workflow (see ``docs/automotive-adas/sysml/index.rst``):
uv sync --extra render
uv run python docs/automotive-adas/sysml/render_sysml.py
The render script walks every ``.gaphor`` file in the directory and
writes one SVG per diagram. Run on a developer machine that has Cairo /
GTK system libraries; commit the regenerated SVGs. CI / RTD do not run
this step.
The matplotlib ``Agg`` backend pin in ``conf.py`` stays as a defensive
guard for developers who install the ``[render]`` extra in the same
venv they build docs from — without it, the presence of PyGObject
flips matplotlib to the GTK4 backend and the build hangs at
"writing output... [4%]".
For real SysML 1.5 XMI files from Cameo / Papyrus / MagicDraw / Rhapsody,
the recommended path is now to export individual diagrams to SVG from
the source tool (all of them support this out of the box), commit the
SVG, and reference it the same way as the Gaphor-rendered example. No
``.gaphor`` conversion needed.
|
Updated to address the two issues: 1. Cairo / Gaphor build dependency removed. The doc build no longer touches Gaphor at all:
2. BDD layout fixed. The previous Python authoring placed New rendering workflow (documented in uv sync --extra render
uv run python docs/automotive-adas/sysml/render_sysml.pyWalks every For real SysML 1.5 XMI (Cameo / Papyrus / MagicDraw / Rhapsody), the recommended path is now: export individual diagrams to SVG from the source tool (all of them support this out of the box), commit the SVG, reference it via Other options I explored before settling on this: PlantUML stereotype mimicry (text-only but not real SysML), Kroki online rendering (no native SysML support), Eclipse Papyrus headless export (heavyweight Java/Eclipse install), Drawio CLI (basic SysML stencils only). The "pre-render and commit" approach was the only one that meets both "no compiler on the user machine" and "ingests real SysML 1.5". |
Summary
Demonstrates that
.. diagram::fromgaphor.extensions.sphinxworks the same way as.. uml::does today — it can be embedded directly inside a sphinx-needsarch::item and renders to SVG + PDF on every build. Prototype intended for a customer SysML 1.5 / 1.6 showcase.What this wires up
gaphor>=3.3.2as a dependency andgaphor.extensions.sphinxindocs/conf.pywith agaphor_modelsmapping.docs/automotive-adas/sysml/:adas-tsr-bdd.gaphor— generated byauthor_adas_bdd.py(Gaphor Python API). A Block Definition Diagram forTrafficSignRecognitiondecomposed intoFrontCamera/SignInterpreter/VehicleControl.sysml-car.gaphor— Gaphor's stock SysML example, dropped in unchanged to prove a third-party.gaphorfile works as-is.ARCH_007insys_3_sys_arch.rst, alongside the existing PlantUML view..readthedocs.yamlapt packages required by PyGObject + Cairo (libgirepository, libcairo2-dev, pkg-config, python3-dev, gir1.2-pango-1.0).automotive-adas/sysml/index.rstpage that explains the integration, the authoring workflow, and the SysML 1.5 XMI conversion question.Non-obvious fix
Installing Gaphor pulls in PyGObject. With PyGObject available, matplotlib auto-selects the
gtk4aggbackend, which then hangs the build at "writing output… [4%]" on any headless host (CI, RTD, sandboxes) because GDK fails to open a surface. Pinnedmatplotlib.use(\"Agg\")early inconf.pybefore any extension imports it. Without this the build hangs silently.On SysML 1.5 / Gaphor
.gaphorformat is XML but is not XMI: different namespace (https://gaphor.org/model), different schema, and it bundles per-diagram presentation/layout that XMI lacks..gaphorconverter.Test plan
uv run sphinx-build -W -b html docs docs/_build/htmlsucceeds (warnings-as-errors, matching RTD'sfail_on_warning: true).docs/_build/html/gaphor/and the SVGs are picked up under_images/.ARCH_007insys_3_sys_arch.htmlshows the BDD figure inside the need's content cell.sysml/index.htmlshows thesysml-carfigure rendered from an unmodified Gaphor example file.uv run python docs/automotive-adas/sysml/author_adas_bdd.py— should regenerateadas-tsr-bdd.gaphordeterministically.Notes for review
adas-tsr-bdd.gaphoris text/XML and tracked as code rather than a binary artifact. Re-run the authoring script after any structural change.