Demo page details
Page source code: demo_details.rst
1{% set page="demo_details.rst" %}
2{% include "demo_page_header.rst" with context %}
3
4🔍 Demo details
5===============
6This page gives some details about extensions, configurations and other important files, which were used
7to define this documentation project.
8
9
10Extensions
11----------
12
13:`Sphinx-Needs <https://sphinx-needs.readthedocs.io>`__:
14 Used to create and link objects in the documentation, mainly requirements, specifications and tests.
15 Provides also features to filter and represent the objects in tables and flow charts.
16
17:`Sphinx-Test-Reports <https://sphinx-test-reports.readthedocs.io>`__:
18 Loads test-results/runs into a Sphinx project, by reading a junit-based result file.
19 Is based on top of Sphinx-Needs.
20
21:`Sphinx-Design <https://sphinx-design.readthedocs.io>`__:
22 Provides features to layout the content or to use dropdown, buttons or tabs.
23
24:`Furo <https://pradyunsg.me/furo/>`__:
25 The Sphinx theme for this documentation.
26
27:`Sphinxcontrib-PlantUML <https://github.com/sphinx-contrib/plantuml>`__:
28 Allows to use `PlantUML <https://plantuml.com/>`__ inside a Sphinx project. Used to create all kinds of diagrams.
29 Also Sphinx-Needs features like ``needflow`` are based on it.
30
31:`Sphinx-SimplePDF <https://sphinx-simplepdf.readthedocs.io/>`__:
32 Provides a Sphinx builder to create a beautiful PDF out of the documentation.
33
34:`Sphinx-Preview <https://sphinx-preview.readthedocs.io>`__:
35 Allows you to get a quick preview of a link without leaving the page.
36 Especially useful for getting a quick impression of linked Sphinx-Needs objects.
37
38Configurations
39--------------
40
41pyproject.toml
42~~~~~~~~~~~~~~
43Used to specify project metadata and install all needed packages for the used Python environment.
44
45The file will be consumed when calling::
46
47 pip install .
48
49or::
50
51 uv sync
52
53conf.py
54~~~~~~~
55The whole configuration file of this project.
56
57Details are explained as comments in the file itself.
58
59.. literalinclude:: conf.py
60 :language: python
61 :linenos:
62
63Templates
64---------
65
66all_post
67~~~~~~~~
68Adds the "Object traceability details" under each object.
69
70.. literalinclude:: needs_templates/all_post.need
71 :language: rst
72 :linenos:
73
74Includes
75--------
76
77demo_page_header
78~~~~~~~~~~~~~~~~
79
80This is used to add the "Demo page details" on top of each page.
81
82.. literalinclude:: demo_page_header.rst
83 :language: rst
84 :linenos:
🔍 Demo details¶
This page gives some details about extensions, configurations and other important files, which were used to define this documentation project.
Extensions¶
- Sphinx-Needs:
Used to create and link objects in the documentation, mainly requirements, specifications and tests. Provides also features to filter and represent the objects in tables and flow charts.
- Sphinx-Test-Reports:
Loads test-results/runs into a Sphinx project, by reading a junit-based result file. Is based on top of Sphinx-Needs.
- Sphinx-Design:
Provides features to layout the content or to use dropdown, buttons or tabs.
- Furo:
The Sphinx theme for this documentation.
- Sphinxcontrib-PlantUML:
Allows to use PlantUML inside a Sphinx project. Used to create all kinds of diagrams. Also Sphinx-Needs features like
needfloware based on it.- Sphinx-SimplePDF:
Provides a Sphinx builder to create a beautiful PDF out of the documentation.
- Sphinx-Preview:
Allows you to get a quick preview of a link without leaving the page. Especially useful for getting a quick impression of linked Sphinx-Needs objects.
Configurations¶
pyproject.toml¶
Used to specify project metadata and install all needed packages for the used Python environment.
The file will be consumed when calling:
pip install .
or:
uv sync
conf.py¶
The whole configuration file of this project.
Details are explained as comments in the file itself.
1# Configuration file for the Sphinx documentation builder.
2#
3# For the full list of built-in configuration values, see the documentation:
4# https://www.sphinx-doc.org/en/master/usage/configuration.html
5import os
6import shutil
7import sys
8
9import jinja2
10
11# We need to make Python aware of our project source code, which is stored outside `/docs`,
12# under `src/`
13code_path = os.path.join(os.path.dirname(__file__), "../", "src/python/")
14sys.path.append(code_path)
15print(f"CODE_PATH: {code_path}")
16
17
18# -- Project information -----------------------------------------------------
19# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
20
21project = "Sphinx-Needs Demo"
22copyright = "2026, team useblocks"
23author = "team useblocks"
24version = "1.0"
25
26# -- General configuration ---------------------------------------------------
27# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
28
29# List of Sphinx extension to use.
30extensions = [
31 "sphinx_needs",
32 "sphinx_codelinks", # Enable code-to-documentation traceability
33 "sphinx_design",
34 "sphinxcontrib.plantuml",
35 "sphinxcontrib.test_reports",
36 "sphinx_simplepdf",
37 "sphinx.ext.autodoc",
38 "sphinx.ext.viewcode",
39 "sphinx_preview",
40 "sphinx_design",
41 "ubt_sphinx",
42]
43
44###############################################################################
45# ubTrace Config
46# ubtrace.useblocks.com
47###############################################################################
48ubtrace_organization = "useblocks"
49ubtrace_project = "sphinx-needs-demo"
50ubtrace_version = "main"
51
52ubtrace_theme_options = {
53 "repo_url": "https://github.com/useblocks/sphinx-needs-demo",
54 "edit_uri": "edit/main/docs/",
55 "view_source_uri": "blob/main/docs/",
56 "logo": {
57 "desktop": "_images/sphinx-needs-logo.png",
58 "mobile": "_images/sphinx-needs-logo.png"
59 }
60}
61
62# Sphinx-Needs Variant Data Configuration
63# Default configuration for eu_left
64# Can be overridden with: sphinx-build -D needs_variant_data_file=variants/eu_right.json
65needs_variant_data_file = "variants/eu_left.json"
66
67# A -D override is applied by Sphinx *after* conf.py runs. Sphinx-Needs reads the
68# final value on its own, but ubtrace_dimensions is computed here, so we honor a
69# -D value from argv to keep it in sync with the selected variant.
70for _arg in sys.argv:
71 if _arg.startswith("needs_variant_data_file="):
72 needs_variant_data_file = _arg.split("=", 1)[1]
73
74# Read the selected variant file to feed ubtrace_dimensions.
75import json
76
77with open(os.path.join(os.path.dirname(__file__), needs_variant_data_file)) as f:
78 _variant_data = json.load(f)
79
80ubtrace_dimensions = {
81 "area": _variant_data["region"]["area"],
82 "steering": _variant_data["vehicle"]["steering_side"]
83}
84
85
86###############################################################################
87# SPHINX-NEEDS Config START
88###############################################################################
89
90# Read the configuration from an external TOML file.
91# This makes it possible to use ubCode and its tools directly with
92# the project. Declarative configuration formats are also preferred as they
93# cannot contain logic and can be consumed by almost all languages.
94needs_from_toml = "ubproject.toml"
95
96###############################################################################
97# SPHINX-NEEDS Config END
98###############################################################################
99
100
101###############################################################################
102# SPHINX-CODELINKS Config START
103###############################################################################
104
105# Read the codelinks configuration from the same TOML file.
106# This enables traceability between source code and documentation.
107# Docs: https://codelinks.useblocks.com/
108src_trace_config_from_toml = "ubproject.toml"
109
110###############################################################################
111# SPHINX-CODELINKS Config END
112###############################################################################
113
114
115###############################################################################
116# SPHINX-TEST-REPORTS Config START
117###############################################################################
118
119# Override the default test-case need of Sphinx-Test-Reports, so that is called
120# ``test_run`` instead.
121# Docs: https://sphinx-test-reports.readthedocs.io/en/latest/configuration.html#tr-case
122tr_case = ["test-run", "testrun", "Test-Run", "TR_", "#999999", "node"]
123
124# Use a different field name for test report files to avoid conflict with codelinks
125# Default is "file" but sphinx-codelinks also uses "file" for source code paths
126tr_file_option = "test_file"
127
128###############################################################################
129# SPHINX-TEST-REPORTS Config END
130###############################################################################
131
132# The config for the preview features, which allows to "sneak" into a link.
133# Docs: https://sphinx-preview.readthedocs.io/en/latest/#configuration
134preview_config = {
135 # Add a preview icon only for this type of links
136 # This is very theme and HTML specific. In this case the Furo main article area.
137 "selector": "article#furo-main-content a",
138 # A list of selectors, where no preview icon shall be added, because it makes often no sense.
139 # For instance the own ID of a need object, or the link on an image to open the image.
140 "not_selector": "div.needs_head a, h1 a, h2 a, a.headerlink, a.back-to-top, a.image-reference, em.sig-param a, a.paginate_button, a.sd-btn, a[href*='#L'], div.highlight a",
141 "set_icon": True,
142 "icon_only": True,
143 "icon_click": True,
144 "icon": "🔍",
145 "width": 600,
146 "height": 400,
147 "offset": {"left": 0, "top": 0},
148 "timeout": 0,
149}
150
151templates_path = ["_templates"]
152
153# Use a custom test-report template that removes the broken self-referencing literalinclude
154tr_report_template = "_static/test_report_template.txt"
155
156# List of files/folder to ignore.
157# Sphinx builds all ``.rst`` files under ``/docs``, no matte if they are part
158# of a toctree or not. So as we have some rst-templates, we need to tell Sphinx to ignore
159# these files.
160exclude_patterns = [
161 "_build",
162 "Thumbs.db",
163 ".DS_Store",
164 "demo_page_header.rst",
165 "demo_hints",
166]
167
168# PlantUML renders node/graph diagrams via Graphviz. If `dot` is missing,
169# PlantUML embeds the error inside the generated SVG instead of failing the
170# build, which sphinx-build -W cannot catch. Fail fast at config load time.
171if shutil.which("dot") is None:
172 raise RuntimeError(
173 "Graphviz 'dot' executable not found on PATH. "
174 "PlantUML requires it to render diagrams. Install graphviz "
175 "(e.g. 'apt-get install graphviz') and retry."
176 )
177
178# We bring our own plantuml jar file.
179# These options tell Sphinxcontrib-PlantUML we it can find this file.
180local_plantuml_path = os.path.join(
181 os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar"
182)
183plantuml = f"java -Djava.awt.headless=true -jar {local_plantuml_path}"
184# plantuml_output_format = 'png'
185plantuml_output_format = "svg_img"
186
187
188# -- Options for HTML output -------------------------------------------------
189# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
190
191html_theme = "furo"
192
193html_static_path = ["_static"]
194
195html_logo = "_images/sphinx-needs-logo.png"
196html_favicon = "_images/sphinx-needs-logo.svg"
197
198html_theme_options = {
199 "sidebar_hide_name": True,
200 "top_of_page_buttons": ["view", "edit"],
201 "source_repository": "https://github.com/useblocks/sphinx-needs-demo",
202 "source_branch": "main",
203 "source_directory": "docs/",
204 "footer_icons": [
205 {
206 "name": "GitHub",
207 "url": "https://github.com/useblocks/sphinx-needs-demo",
208 "html": """
209 <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
210 <path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
211 </svg>
212 """,
213 "class": "",
214 },
215 ],
216}
217
218html_css_files = [
219 "furo.css",
220 "custom.css",
221]
222
223# Some special vodoo to render each rst-file by jinja, before it gets handled by Sphinx.
224# This allows us to use the powerfull jinja-features to create content in a loop, react on
225# external data input, or include templates with parameters.
226# In our case we use it mostly to set the "demo page details" header in each page.
227# A good blog post about this can be found here:
228# Docs: https://ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/
229def rstjinja(app, docname, source):
230 """
231 Render our pages as a jinja template for fancy templating goodness.
232
233 This voodoo is needed as we use the jinja command ``include``, which searches
234 for the referenced file. This works locally, but has't worked on ReadTheDocs.
235 These more "complex" cwd and Template-Folder operations make it working.
236 """
237 old_cwd = os.getcwd()
238
239 jinja2.FileSystemLoader(app.confdir)
240 os.chdir(os.path.dirname(__file__))
241 src = source[0]
242 env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
243 template = env.from_string(src)
244 # template = jinja2.Template(src, autoescape=True, environemnt=env)
245 rendered = template.render(**app.config.html_context)
246 source[0] = rendered
247 os.chdir(old_cwd)
248
249
250# This function allows us to register any kind of black magic for Sphinx :)
251def setup(app):
252 # We connect our jinja-function from above with the "source-read" event of Sphinx,
253 # which gets called for every file before Sphinx starts to handle the file on its own.
254 # This allows us to manipulate the content.
255 app.connect("source-read", rstjinja)
Templates¶
all_post¶
Adds the “Object traceability details” under each object.
1.. if-builder:: html
2
3 .. warning::
4 :title: Object traceability details: {{title}}
5 :collapsible:
6
7 .. needflow::
8 :filter: "{{id}}"==id or "{{id}}" in links or "{{id}}" in links_back or "{{id}}" in author_back
9
10 .. needtable::
11 :style: table
12 :filter: "{{id}}"==id or "{{id}}" in links or "{{id}}" in links_back or "{{id}}" in author_back
13 :columns: id, title, type, author
Includes¶
demo_page_header¶
This is used to add the “Demo page details” on top of each page.
1.. if-builder:: html
2
3 .. dropdown:: Demo page details
4 :icon: light-bulb
5 :color: success
6
7 **Page source code: {{page}}**
8
9 .. literalinclude:: {{page}}
10 :language: rst
11 :linenos: