Skip to content

Commit bd02f89

Browse files
feat: draw_metamodel in docs
1 parent 9cecec5 commit bd02f89

File tree

7 files changed

+544
-13
lines changed

7 files changed

+544
-13
lines changed

docs/internals/requirements/requirements.rst

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,19 @@ This section provides an overview of current process requirements and their clar
221221
* all architecture elements defined in :need:`tool_req__docs_arch_types`.
222222
* all safety analysis elements defined in :need:`tool_req__docs_saf_types`.
223223

224+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
225+
226+
.. needuml::
227+
228+
{{draw_metamodel(
229+
[
230+
"stkh_req", "feat_req", "comp_req", "aou_req",
231+
"feat_arc_sta", "feat", "logic_arc_int", "logic_arc_int_op", "comp_arc_sta", "comp", "real_arc_int", "real_arc_int_op",
232+
"feat_saf_fmea", "comp_saf_fmea", "feat_saf_dfa", "comp_saf_dfa",
233+
],
234+
attributes=["status"],
235+
)}}
236+
224237

225238

226239
----------
@@ -271,6 +284,12 @@ Versioning
271284
* Tool Verification Report (doc_tool)
272285
* Change Request is also a generic document
273286

287+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
288+
289+
.. needuml::
290+
291+
{{draw_metamodel(types=["document", "doc_tool"])}}
292+
274293
.. tool_req:: Mandatory attributes of Generic Documents
275294
:id: tool_req__docs_doc_generic_mandatory
276295
:tags: Documents
@@ -287,6 +306,12 @@ Versioning
287306
* safety
288307
* realizes
289308

309+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
310+
311+
.. needuml::
312+
313+
{{draw_metamodel("document", attributes=["status", "security", "safety", "realizes"])}}
314+
290315
.. tool_req:: Mandatory Document attributes
291316
:id: tool_req__docs_doc_attr
292317
:tags: Documents
@@ -307,6 +332,11 @@ Versioning
307332
* approver
308333
* reviewer
309334

335+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
336+
337+
.. needuml::
338+
339+
{{draw_metamodel(["document", "doc_tool"], attributes=["title", "author", "approver", "reviewer"])}}
310340

311341
.. tool_req:: Document author is autofilled
312342
:id: tool_req__docs_doc_attr_author_autofill
@@ -388,6 +418,16 @@ Mapping
388418
* Process requirement (gd_req)
389419
* Tool requirement (tool_req)
390420

421+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
422+
423+
.. needuml::
424+
425+
{{draw_metamodel(
426+
[
427+
"stkh_req", "feat_req", "comp_req", "aou_req", "gd_req", "tool_req",
428+
],
429+
)}}
430+
391431
-------------------------
392432
🏷️ Attributes
393433
-------------------------
@@ -401,6 +441,13 @@ Mapping
401441

402442
Docs-as-Code shall enforce that each stakeholder requirement (stkh_req) contains a ``rationale`` attribute.
403443

444+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
445+
446+
.. needuml::
447+
448+
{{draw_metamodel(["stkh_req"], attributes=["rationale"])}}
449+
450+
404451
.. tool_req:: Enforces requirement type classification
405452
:id: tool_req__docs_req_attr_reqtype
406453
:tags: Requirements
@@ -507,6 +554,18 @@ Mapping
507554
.. note::
508555
Certain tool requirements do not have a matching process requirement.
509556

557+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
558+
559+
.. needuml::
560+
561+
{{draw_metamodel(
562+
[
563+
"stkh_req", "feat_req", "comp_req", "gd_req", "tool_req", "workflow"
564+
],
565+
links="satisfies",
566+
)}}
567+
568+
510569
.. tool_req:: Safety: enforce safe linking
511570
:id: tool_req__docs_common_attr_safety_link_check
512571
:tags: Common Attributes
@@ -544,6 +603,16 @@ Mapping
544603
* Interface (real_arc_int)
545604
* Interface Operation (real_arc_int_op)
546605

606+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
607+
608+
.. needuml::
609+
610+
{{draw_metamodel(
611+
[
612+
"feat_arc_sta", "feat", "logic_arc_int", "logic_arc_int_op", "comp_arc_sta", "comp", "real_arc_int", "real_arc_int_op",
613+
],
614+
)}}
615+
547616
--------------------------
548617
Architecture Attributes
549618
--------------------------
@@ -564,8 +633,24 @@ Architecture Attributes
564633
* Safety
565634
* Security
566635
* Status
567-
* UID
636+
* ID (implicitly enforced by sphinx-needs)
568637

638+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
639+
640+
.. needuml::
641+
642+
{{draw_metamodel(
643+
[
644+
"feat_arc_sta", "feat", "logic_arc_int", "logic_arc_int_op", "comp_arc_sta", "comp", "real_arc_int", "real_arc_int_op",
645+
],
646+
attributes=[
647+
"fulfils",
648+
"safety",
649+
"security",
650+
"status",
651+
"id",
652+
],
653+
)}}
569654

570655

571656
------------------------
@@ -601,6 +686,24 @@ Architecture Attributes
601686
real_arc_int comp_req
602687
==================================== ==========================================
603688

689+
.. admonition:: How is it currently implemented in the current docs-as-code metamodel.yml?
690+
691+
.. needuml::
692+
693+
{{draw_metamodel(
694+
[
695+
"feat_req",
696+
"comp_req",
697+
"feat_arc_sta",
698+
"feat_arc_dyn",
699+
"logic_arc_int"
700+
"comp_arc_sta",
701+
"comp_arc_dyn",
702+
"real_arc_int"
703+
],
704+
links=["fulfils"],
705+
attributes=False
706+
)}}
604707

605708
.. tool_req:: Ensure safety architecture elements link a safety requirement
606709
:id: tool_req__docs_arch_link_safety_to_req
@@ -675,6 +778,7 @@ Architecture Attributes
675778
but are still defined as architectural elements, which means they have the properties of
676779
architectural elements.
677780

781+
678782
💻 Detailed Design & Code
679783
##########################
680784

src/extensions/score_draw_uml_funcs/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060

6161

6262
def setup(app: Sphinx) -> dict[str, object]:
63-
app.config.needs_render_context = draw_uml_function_context
63+
# Extend the needs_render_context with our drawing functions
64+
app.config.needs_render_context = (
65+
app.config.needs_render_context or {}
66+
) | draw_uml_function_context
67+
6468
return {
6569
"version": "0.1",
6670
"parallel_read_safe": True,

src/extensions/score_metamodel/__init__.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
from pathlib import Path
1818

1919
from sphinx.application import Sphinx
20+
from sphinx.environment import BuildEnvironment
2021
from sphinx_needs import logging
2122
from sphinx_needs.data import NeedsInfoType, NeedsView, SphinxNeedsData
2223

24+
from src.extensions.score_metamodel.draw_metamodel import DrawMetamodel
2325
from src.extensions.score_metamodel.external_needs import connect_external_needs
2426
from src.extensions.score_metamodel.log import CheckLogger
2527

@@ -101,13 +103,6 @@ def _run_checks(app: Sphinx, exception: Exception | None) -> None:
101103
if exception:
102104
return
103105

104-
# First of all postprocess the need links to convert
105-
# type names into actual need types.
106-
# This must be done before any checks are run.
107-
# And it must be done after config was hashed, otherwise
108-
# the config hash would include recusive linking between types.
109-
postprocess_need_links(app.config.needs_types)
110-
111106
# Filter out external needs, as checks are only intended to be run
112107
# on internal needs.
113108
needs_all_needs = SphinxNeedsData(app.env).get_needs_view()
@@ -201,13 +196,17 @@ def _resolve_linkable_types(
201196
return linkable_types
202197

203198

204-
def postprocess_need_links(needs_types_list: list[ScoreNeedType]):
199+
def postprocess_need_links(
200+
app: Sphinx, _env: BuildEnvironment, _docnames: list[str]
201+
) -> None:
205202
"""Convert link option strings into lists of target need types.
206203
207204
If a link value starts with '^' it is treated as a regex and left
208205
unchanged. Otherwise it is a comma-separated list of type names which
209206
are resolved to the corresponding ScoreNeedTypes.
210207
"""
208+
needs_types_list: list[ScoreNeedType] = app.config.needs_types
209+
211210
for need_type in needs_types_list:
212211
try:
213212
link_dicts = (
@@ -250,11 +249,25 @@ def setup(app: Sphinx) -> dict[str, str | bool]:
250249
app.config.needs_reproducible_json = True
251250
app.config.needs_json_remove_defaults = True
252251

252+
# Extend the needs_render_context with our drawing functions
253+
app.config.needs_render_context = (app.config.needs_render_context or {}) | {
254+
"draw_metamodel": DrawMetamodel(app.config),
255+
}
256+
253257
# sphinx-collections runs on default prio 500.
254258
# We need to populate the sphinx-collections config before that happens.
255259
# --> 499
256260
_ = app.connect("config-inited", connect_external_needs, priority=499)
257261

262+
# Postprocess the need links to convert type names into actual need types.
263+
# This must be done before any checks are run.
264+
# And it must be done after config was hashed, otherwise
265+
# the config hash would include recusive linking between types.
266+
# Note that needs_config_writer also runs at 999. Our postprocessing must happen
267+
# after needs_config_writer has done its job (for now).
268+
# So needs_config_writer must be included before score_metamodel in extensions list.
269+
_ = app.connect("env-before-read-docs", postprocess_need_links, priority=999)
270+
258271
discover_checks()
259272

260273
app.add_config_value(

0 commit comments

Comments
 (0)