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/")
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
44ubtrace_organization = "useblocks"
45ubtrace_project = "sphinx-needs-demo"
46ubtrace_version = "main"
47
48###############################################################################
49# SPHINX-NEEDS Config START
50###############################################################################
51
52# Read the configuration from an external TOML file.
53# This makes it possible to use ubCode and its tools directly with
54# the project. Declarative configuration formats are also preferred as they
55# cannot contain logic and can be consumed by almost all languages.
56needs_from_toml = "ubproject.toml"
57
58###############################################################################
59# SPHINX-NEEDS Config END
60###############################################################################
61
62
63###############################################################################
64# SPHINX-CODELINKS Config START
65###############################################################################
66
67# Read the codelinks configuration from the same TOML file.
68# This enables traceability between source code and documentation.
69# Docs: https://codelinks.useblocks.com/
70src_trace_config_from_toml = "ubproject.toml"
71
72###############################################################################
73# SPHINX-CODELINKS Config END
74###############################################################################
75
76
77###############################################################################
78# SPHINX-TEST-REPORTS Config START
79###############################################################################
80
81# Override the default test-case need of Sphinx-Test-Reports, so that is called
82# ``test_run`` instead.
83# Docs: https://sphinx-test-reports.readthedocs.io/en/latest/configuration.html#tr-case
84tr_case = ["test-run", "testrun", "Test-Run", "TR_", "#999999", "node"]
85
86# Use a different field name for test report files to avoid conflict with codelinks
87# Default is "file" but sphinx-codelinks also uses "file" for source code paths
88tr_file_option = "test_file"
89
90###############################################################################
91# SPHINX-TEST-REPORTS Config END
92###############################################################################
93
94# The config for the preview features, which allows to "sneak" into a link.
95# Docs: https://sphinx-preview.readthedocs.io/en/latest/#configuration
96preview_config = {
97 # Add a preview icon only for this type of links
98 # This is very theme and HTML specific. In this case the Furo main article area.
99 "selector": "article#furo-main-content a",
100 # A list of selectors, where no preview icon shall be added, because it makes often no sense.
101 # For instance the own ID of a need object, or the link on an image to open the image.
102 "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",
103 "set_icon": True,
104 "icon_only": True,
105 "icon_click": True,
106 "icon": "🔍",
107 "width": 600,
108 "height": 400,
109 "offset": {"left": 0, "top": 0},
110 "timeout": 0,
111}
112
113templates_path = ["_templates"]
114
115# List of files/folder to ignore.
116# Sphinx builds all ``.rst`` files under ``/docs``, no matte if they are part
117# of a toctree or not. So as we have some rst-templates, we need to tell Sphinx to ignore
118# these files.
119exclude_patterns = [
120 "_build",
121 "Thumbs.db",
122 ".DS_Store",
123 "demo_page_header.rst",
124 "demo_hints",
125]
126
127# PlantUML renders node/graph diagrams via Graphviz. If `dot` is missing,
128# PlantUML embeds the error inside the generated SVG instead of failing the
129# build, which sphinx-build -W cannot catch. Fail fast at config load time.
130if shutil.which("dot") is None:
131 raise RuntimeError(
132 "Graphviz 'dot' executable not found on PATH. "
133 "PlantUML requires it to render diagrams. Install graphviz "
134 "(e.g. 'apt-get install graphviz') and retry."
135 )
136
137# We bring our own plantuml jar file.
138# These options tell Sphinxcontrib-PlantUML we it can find this file.
139local_plantuml_path = os.path.join(
140 os.path.dirname(__file__), "utils", "plantuml-1.2022.14.jar"
141)
142plantuml = f"java -Djava.awt.headless=true -jar {local_plantuml_path}"
143# plantuml_output_format = 'png'
144plantuml_output_format = "svg_img"
145
146
147# -- Options for HTML output -------------------------------------------------
148# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
149
150html_theme = "furo"
151
152html_static_path = ["_static"]
153
154html_logo = "_images/sphinx-needs-logo.png"
155html_favicon = "_images/sphinx-needs-logo.svg"
156
157html_theme_options = {
158 "sidebar_hide_name": True,
159 "top_of_page_buttons": ["view", "edit"],
160 "source_repository": "https://github.com/useblocks/sphinx-needs-demo",
161 "source_branch": "main",
162 "source_directory": "docs/",
163 "footer_icons": [
164 {
165 "name": "GitHub",
166 "url": "https://github.com/useblocks/sphinx-needs-demo",
167 "html": """
168 <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
169 <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>
170 </svg>
171 """,
172 "class": "",
173 },
174 ],
175}
176
177html_css_files = [
178 "furo.css",
179 "custom.css",
180]
181
182# Some special vodoo to render each rst-file by jinja, before it gets handled by Sphinx.
183# This allows us to use the powerfull jinja-features to create content in a loop, react on
184# external data input, or include templates with parameters.
185# In our case we use it mostly to set the "demo page details" header in each page.
186# A good blog post about this can be found here:
187# Docs: https://ericholscher.com/blog/2016/jul/25/integrating-jinja-rst-sphinx/
188def rstjinja(app, docname, source):
189 """
190 Render our pages as a jinja template for fancy templating goodness.
191
192 This voodoo is needed as we use the jinja command ``include``, which searches
193 for the referenced file. This works locally, but has't worked on ReadTheDocs.
194 These more "complex" cwd and Template-Folder operations make it working.
195 """
196 old_cwd = os.getcwd()
197
198 jinja2.FileSystemLoader(app.confdir)
199 os.chdir(os.path.dirname(__file__))
200 src = source[0]
201 env = jinja2.Environment(loader=jinja2.FileSystemLoader("."))
202 template = env.from_string(src)
203 # template = jinja2.Template(src, autoescape=True, environemnt=env)
204 rendered = template.render(**app.config.html_context)
205 source[0] = rendered
206 os.chdir(old_cwd)
207
208
209# This function allows us to register any kind of black magic for Sphinx :)
210def setup(app):
211 # We connect our jinja-function from above with the "source-read" event of Sphinx,
212 # which gets called for every file before Sphinx starts to handle the file on its own.
213 # This allows us to manipulate the content.
214 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: