-
Notifications
You must be signed in to change notification settings - Fork 3
264 update to latest sphinx needs version #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "7.17.0" | ||
| __version__ = "8.0.0-rc.1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |
| import json | ||
| import os | ||
| import datetime | ||
| import re | ||
|
|
||
| from spl_core.report_generation.spl_sphinx import SplSphinx | ||
| from spl_core.report_generation.spl_html_settings import html_theme, html_show_sourcelink, html_theme_options # noqa: F401 | ||
|
|
||
| day = datetime.date.today() | ||
| # meta data ################################################################# | ||
|
|
@@ -42,136 +44,28 @@ | |
| # Omit "documentation" in title | ||
| html_title = f"{project} {release}" | ||
|
|
||
| html_theme = "sphinx_rtd_theme" | ||
|
|
||
| # Show hyper link which leeds to the source of page displayed | ||
| html_show_sourcelink = True | ||
|
|
||
| html_theme_options = { | ||
| "canonical_url": "", | ||
| "analytics_id": "", # Provided by Google in your dashboard | ||
| "display_version": True, | ||
| "prev_next_buttons_location": "bottom", | ||
| "style_external_links": True, | ||
| "logo_only": False, | ||
| "style_nav_header_background": "white", | ||
| # Toc options | ||
| "collapse_navigation": True, | ||
| "sticky_navigation": True, | ||
| "navigation_depth": 6, | ||
| "includehidden": True, | ||
| "titles_only": False, | ||
| } | ||
|
|
||
| # EXTENSIONS AND THEIR CONFIGS ############################################## | ||
| # Use default SPL HTML theme configuration (imported from spl_html_settings) | ||
| # Can be overridden after import if needed | ||
|
|
||
| # extensions and their configuration ######################################### | ||
| extensions = [] | ||
|
|
||
| extensions.append("sphinx_rtd_size") | ||
| sphinx_rtd_size_width = "90%" | ||
|
|
||
| extensions.append("sphinxcontrib.mermaid") | ||
|
|
||
| extensions.append("sphinx_needs") | ||
|
|
||
| extensions.append("sphinxcontrib.test_reports") | ||
| tr_report_template = "doc/test_report_template.txt" | ||
|
|
||
|
|
||
| def tr_link(app, need, needs, first_option_name, second_option_name, *args, **kwargs): | ||
| """Make links between 'needs'. In comparison to the default 'tr_link' function, | ||
| this function supports regular expression pattern matching.""" | ||
| if first_option_name not in need: | ||
| return "" | ||
| # Get the value of the 'first_option_name' | ||
| first_option_value = need[first_option_name] | ||
|
|
||
| links = [] | ||
| for need_target in needs.values(): | ||
| # Skip linking to itself | ||
| if need_target["id"] == need["id"]: | ||
| continue | ||
| if second_option_name not in need_target: | ||
| continue | ||
|
|
||
| if first_option_value is not None and len(first_option_value) > 0: | ||
| second_option_value = need_target[second_option_name] | ||
| if second_option_value is not None and len(second_option_value) > 0: | ||
| if first_option_value == second_option_value: | ||
| links.append(need_target["id"]) | ||
| # if the first option value has a *, use regex matching | ||
| elif "*" in first_option_value: | ||
| if re.match(first_option_value, second_option_value): | ||
| links.append(need_target["id"]) | ||
|
|
||
| return links | ||
|
|
||
|
|
||
| needs_functions = [tr_link] | ||
|
|
||
| extensions.append("sphinx.ext.todo") | ||
|
|
||
| # Render Your Data Readable ################################################## | ||
| # Enables adding Jupyter notebooks to toctree | ||
| # @see https://sphinxcontribdatatemplates.readthedocs.io/en/latest/index.html | ||
| extensions.append("sphinxcontrib.datatemplates") | ||
|
|
||
| # needs_types - this option allows the setup of own need types like bugs, user_stories and more. | ||
| needs_types = [ | ||
| dict(directive="req", title="Requirement", prefix="R_", color="#BFD8D2", style="node"), | ||
| dict( | ||
| directive="spec", | ||
| title="Specification", | ||
| prefix="S_", | ||
| color="#FEDCD2", | ||
| style="node", | ||
| ), | ||
| dict( | ||
| directive="impl", | ||
| title="Implementation", | ||
| prefix="I_", | ||
| color="#DF744A", | ||
| style="node", | ||
| ), | ||
| dict(directive="test", title="Test Case", prefix="T_", color="#DCB239", style="node"), | ||
| ] | ||
|
|
||
| # Define own options | ||
| needs_extra_options = ["integrity"] | ||
|
|
||
| # Define own link types | ||
| needs_extra_links = [ | ||
| # SWE.3 BP.5: link from Implementation (Software unit) to Specification (Software detailed design) | ||
| # AND | ||
| # SWE.2 BP.7: link from Requirements (Software Requirement) to Architecture (Software Architecture) | ||
| {"option": "implements", "incoming": "is implemented by", "outgoing": "implements"}, | ||
| # SWE.4 BP.5: link from Test Case (Unit test specification) to Specification (Software detailed design) | ||
| {"option": "tests", "incoming": "is tested by", "outgoing": "tests"}, | ||
| # SWE.4 BP.5: link from Test Case (Unit test specification) to Test Result (Unit test result) | ||
| {"option": "results", "incoming": "is resulted from", "outgoing": "results"}, | ||
| ] | ||
|
|
||
| # Link tests results to the test cases | ||
| needs_global_options = { | ||
| "results": "[[tr_link('title', 'case')]]", | ||
| } | ||
|
|
||
| # Parse markdown files | ||
| extensions.append("myst_parser") | ||
| myst_enable_extensions = [ | ||
| "colon_fence", | ||
| "deflist", | ||
| "html_admonition", | ||
| "html_image", | ||
| ] | ||
|
|
||
| # The suffix of source filenames. | ||
| source_suffix = [ | ||
| ".rst", | ||
| ".md", | ||
| ] | ||
| # EXTENSIONS AND THEIR CONFIGS ############################################## | ||
|
|
||
| # Get default SPL extensions and their configurations | ||
| extensions = SplSphinx.default_extensions | ||
| extension_configs = SplSphinx.default_extension_configs | ||
|
|
||
| # Apply extension-specific configurations | ||
| sphinx_rtd_size_width = extension_configs["sphinx_rtd_size_width"] | ||
| tr_report_template = extension_configs["tr_report_template"] | ||
| myst_enable_extensions = extension_configs["myst_enable_extensions"] | ||
| source_suffix = extension_configs["source_suffix"] | ||
|
|
||
| # Import default SPL sphinx-needs configuration | ||
| needs_from_toml = ".venv/Lib/site-packages/spl_core/report_generation/ubproject.toml" | ||
| # Additional import required because the configuration references custom functions defined in this module | ||
| needs_functions = SplSphinx.default_needs_functions | ||
| needs_global_options = SplSphinx.default_needs_global_options | ||
|
|
||
| # Provide all config values to jinja | ||
| html_context = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| "build_config": {}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """HTML theme configuration for SPL projects.""" | ||
|
|
||
| # HTML Theme | ||
| html_theme = "sphinx_rtd_theme" | ||
|
|
||
| # Show source links | ||
| html_show_sourcelink = True | ||
|
|
||
| # Read the Docs Theme Options | ||
| html_theme_options = { | ||
| "canonical_url": "", | ||
| "analytics_id": "", | ||
| "display_version": True, | ||
| "prev_next_buttons_location": "bottom", | ||
| "style_external_links": True, | ||
| "logo_only": False, | ||
| "style_nav_header_background": "white", | ||
| "collapse_navigation": True, | ||
| "sticky_navigation": True, | ||
| "navigation_depth": 6, | ||
| "includehidden": True, | ||
| "titles_only": False, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """Centralized Sphinx configuration for SPL projects.""" | ||
|
|
||
| import re | ||
| from typing import Any, ClassVar | ||
|
|
||
| from sphinx.application import Sphinx | ||
| from sphinx_needs.data import NeedsMutable, NeedsView | ||
| from sphinx_needs.need_item import NeedItem, NeedPartItem | ||
|
|
||
|
|
||
| def sple_tr_link( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no way to keep the name of this method |
||
| app: Sphinx, | ||
| need: NeedItem | NeedPartItem, | ||
| needs: NeedsView | NeedsMutable, | ||
| first_option_name: str, | ||
| second_option_name: str, | ||
| *args: Any, | ||
| **kwargs: Any, | ||
| ) -> list[str]: | ||
| """Make links between 'needs'. In comparison to the default 'tr_link' function, | ||
| this function supports regular expression pattern matching.""" | ||
| if first_option_name not in need: | ||
| return [] | ||
| # Get the value of the 'first_option_name' | ||
| first_option_value = need[first_option_name] | ||
|
|
||
| links = [] | ||
| for need_target in needs.values(): | ||
| # Skip linking to itself | ||
| if need_target["id"] == need["id"]: | ||
| continue | ||
| if second_option_name not in need_target: | ||
| continue | ||
|
|
||
| if first_option_value is not None and len(first_option_value) > 0: | ||
| second_option_value = need_target[second_option_name] | ||
| if second_option_value is not None and len(second_option_value) > 0: | ||
| if first_option_value == second_option_value: | ||
| links.append(need_target["id"]) | ||
| # if the first option value has a *, use regex matching | ||
| elif "*" in first_option_value: | ||
| if re.match(first_option_value, second_option_value): | ||
| links.append(need_target["id"]) | ||
|
|
||
| return links | ||
|
|
||
|
|
||
| class SplSphinx: | ||
| """Centralized Sphinx configuration for SPL projects. | ||
|
|
||
| This class provides default configurations for sphinx-needs extension, | ||
| including custom need types, link types, and linking functions. | ||
|
|
||
| All configurations are available as class properties: | ||
| - default_needs_types: Need type configurations (req, spec, impl, test) | ||
| - default_needs_extra_options: Additional need options | ||
| - default_needs_extra_links: Link type configurations for traceability | ||
| - default_needs_global_options: Global options for needs | ||
| - default_needs_functions: Custom needs functions | ||
| - default_extensions: List of Sphinx extensions | ||
| - default_extension_configs: Extension-specific configurations | ||
| """ | ||
|
|
||
| # Needs Global Options - automatically links test results to test cases | ||
| # sphinx-needs 6.x requires FieldDefault format: {"default": ...} | ||
| default_needs_global_options: ClassVar[dict[str, dict[str, str]]] = { | ||
| "results": {"default": "[[sple_tr_link('title', 'case')]]"}, | ||
| } | ||
|
|
||
| # Needs Functions - custom linking functions | ||
| default_needs_functions: ClassVar[list[Any]] = [sple_tr_link] | ||
|
|
||
| # Default Sphinx Extensions | ||
| default_extensions: ClassVar[list[str]] = [ | ||
| "sphinx_rtd_size", | ||
| "sphinxcontrib.mermaid", | ||
| "sphinx_needs", | ||
| "sphinxcontrib.test_reports", | ||
| "sphinx.ext.todo", | ||
| "sphinxcontrib.datatemplates", | ||
| "myst_parser", | ||
| ] | ||
|
|
||
| # Extension-specific configurations | ||
| default_extension_configs: ClassVar[dict[str, str | list[str]]] = { | ||
| "sphinx_rtd_size_width": "90%", | ||
| "tr_report_template": "doc/test_report_template.txt", | ||
| "myst_enable_extensions": [ | ||
| "colon_fence", | ||
| "deflist", | ||
| "html_admonition", | ||
| "html_image", | ||
| ], | ||
| "source_suffix": [ | ||
| ".rst", | ||
| ".md", | ||
| ], | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a Windows only path (
Lib/site-packages). On Linux/macOS it would belib/pythonX.Y/site-packages. It should be resolved dynamically, e.g.: