variants
Selectors, not builds
Sphinx-Needs resolves a variant at build time: a data file, templated fields,
:variant: roles and .. if:: blocks produce a separate document per
variant. req keeps one model and queries it: a claim's applicability is a predicate,
and a context decides which claims apply. The difference is not cosmetic; it changes what
“unknown” means, and what happens to architecture, design, code and tests.
Sphinx-Needs: one build per variant
The upstream ships three JSON files (eu_left, eu_right,
america) and builds with one at a time:
sphinx-build -b html -D needs_variant_data_file=variants/eu_right.json docs _build/eu_right
Inside the document, a variant can change a field value, expand prose, or include a block:
:max_speed: <{ var.region.speed_limit_highway }>
.. if:: var.vehicle.steering_side == "left"
.. swreq:: Left-hand drive turn signal priority
:id: SWREQ_028
.. if:: var.vehicle.steering_side == "right"
.. swreq:: Right-hand drive turn signal priority
:id: SWREQ_029
The two builds are two documents. SWREQ_028 exists in the left build and
SWREQ_029 exists in the right one; neither export holds both. The traceability
table, the needflow, the fields and the conditional prose are all resolved for that build.
Comparing variants means building twice and comparing two outputs.
req: one corpus, a context
The two turn-signal requirements are two claims in the same corpus:
claim_id: REQ-0113
applicability:
- steering_side == left
claim_id: REQ-0136
applicability:
- steering_side == right
.req/variants declares the contexts the release gate must decide:
steering_side=left
steering_side=right
Selection is a query, not a build:
$ req select steering_side=right
REQ-0136 applies
REQ-0113 does not apply
applies 135, does not apply 1, unknown 0
Nothing is copied, forked or regenerated. The same 135 claims, the same design files and the same JUnit links are present in both contexts.
Architecture, design and code
This is where the two models differ most. req does not put a selector on a file. A design
element — an architecture document, a component or a C file — declares req-satisfies:
links to claims; the claim carries the applicability. The variant pair has one element
per side:
design/components/TURN_SIGNAL_LEFT.md→REQ-0113design/components/TURN_SIGNAL_RIGHT.md→REQ-0136
req satisfy has no context and lists all 58 declared links. A gate is a context, and
judges only the links of claims that apply there:
| Invocation | design links judged | why |
|---|---|---|
req gate steering_side=left | 57 of 58 | the right element’s claim does not apply |
req gate steering_side=right | 57 of 58 | the left element’s claim does not apply |
req gate (no context) | 56 of 58 | both variant claims are undecided; 2 undecided in total |
req satisfy | 58 declared | diagnostic over every declaration, no context |
The architecture/component/code element itself is not “variant A” or “variant B”; it is a
design element with a link to a variant-scoped claim. If one design is genuinely shared, one
element links to both claims. If the design is physically different, it is two elements. That is
the whole rule, and it is why the same component overlay can show both elements HOLD while a
gate under left judges only one of them.
Tests
A test link lives on the claim (tests: classname::name), so it inherits the
claim’s applicability. A gate for steering_side=left only requires evidence for
the left claim; the right test can be present in the same report without being counted in that
release. Nothing is deleted from the corpus; the context decides what the gate examines.
The Coffee Machine example uses the same rule with no selector: all 8 claims apply in every context, and the 4 linked claims are judged in both.