Sphinx-Needs Ecosystem

repository·master·Indexed 43 days ago

https://github.com/useblocks/sphinx-needs

A collection of Sphinx extensions for requirements management, traceability, and test reporting. The ecosystem includes sphinx-needs for core requirements, sphinx-mounts for mounting external source trees without copying, sphinx-codelinks for source-code traceability via comment markers, and sphinx-test-reports for converting JUnit, ctest, googletest, and tox-envreport results into Sphinx needs.

Tokens
148.9K
Snippets
479
Records
651
Agent score
55%

What's inside Sphinx-Needs

  1. Overview of sphinx-needs concepts

    master

    Sphinx-Needs is used to define, link, and filter class-like "need-objects". By default, these objects represent:

    • requirements
    • specifications
    • implementations
    • test cases

    These types can be customized via configuration to support other entities like bugs or user stories. The extension also provides powerful tools for analyzing and visualizing needs through directives like needtable, needflow, and needpie.

  2. Overview of CodeLinks components and capabilities

    master

    CodeLinks is a utility designed for fast source code tracing and integration with the Sphinx-Needs ecosystem. It consists of four primary components:

    1. Source code analyzer: Supports multiple programming languages and comment styles.
    2. Generator: Produces various output formats containing extracted markers or needs.
    3. Sphinx extension: Integrates CodeLinks directly with Sphinx-Needs.
    4. CLI application: Drives the analysis and generation processes, suitable for CI/CD pipelines.

    Configuration is managed via a single TOML file used by both the Sphinx extension and the CLI application.

  3. Overview of the Source Analyse module

    master

    The Source Analyse module in Sphinx-CodeLinks extracts documentation-related content from source code comments. It allows developers to embed documentation directly in source code while maintaining a clean separation. It provides both CLI and API interfaces and supports generating structured JSON output for downstream processing.

    Primary Extraction Modes:

    1. Sphinx-Needs ID References: Links between code and requirements/specifications.
    2. One-line Needs: Simplified syntax for creating documentation needs without complex RST.
    3. Marked RST Blocks: Full reStructuredText (RST) content embedded within comments.

    Supported Languages & Comment Styles:

    • C/C++: //, /* */
    • C#: //, /* */, ///
    • Python: #
    • YAML: #
    • Rust: //, /* */, ///
    • Go: //
    • JSONC: //, /* */
    • Bash: #

    Note: Each analysis run can only process one comment style at a time.

  4. Introduction to sphinx-needs

    master

    Overview

    sphinx-needs is a Sphinx extension designed to bring "Engineering-as-Code" to the documentation framework. It allows you to define, link, and analyze engineering objects (such as requirements, specifications, features, and test cases) directly within your Sphinx documentation.

    Key Capabilities

    • Engineering Object Management: Define and track custom objects like requirements or test cases.
    • Safety Standard Compliance: Highly configurable to support strict documentation workflows required by standards like ISO 26262 or DO-178B/C.
    • Extensibility: Provides a built-in API for other extensions to interact with sphinx-needs and extensive configuration options.
    • External Integration: Supports importing and exporting data from external sources like JIRA, GitHub, or spreadsheets.
    • Automated Data Handling: Uses dynamic_functions to manage complex data chains and automatically update data during the documentation generation phase.
    • Architecture Visualization: Integrates with PlantUML to create reusable architecture elements that can be combined into flow diagrams.
  5. Overview of Sphinx CodeLinks features

    master

    Sphinx CodeLinks is a Sphinx extension designed to discover, link, and document source code across different projects. Its core capabilities include:

    • Source Discovery: Automatically finding source files within your project.
    • Analyse: Parsing source code to extract specific markers and their associated metadata.
    • Code Linking: Establishing intelligent links between various code elements.
    • Sphinx Integration: Working seamlessly within your existing Sphinx documentation workflow.
  6. Overview of Sphinx-Test-Reports

    master

    Sphinx-Test-Reports is a Sphinx extension designed to display test results directly within Sphinx documentation. It is particularly useful for projects requiring human-readable documentation of test outcomes and environment configurations (e.g., for safety-critical standards like ISO 26262).

    Key features include:

    • Documenting test files: Automatically document all test cases from a JUnit-based XML file.
    • Documenting test suites: Document specific test suites and their constituent cases.
    • Documenting individual test cases: Document a single test case from a specific file and suite.
    • Creating test reports: Generate comprehensive reports from test files, including analysis tables.
    • Creating test result tables: Generate simple tables of test cases within a file.
    • Documenting test environments: Document the test environment used, based on tox-envreport.
  7. Overview of the sphinx-needs ecosystem

    master

    The sphinx-needs repository is a monorepo managed as a uv workspace containing several specialized Sphinx extensions. While they are developed together to ensure compatibility, they are distributed as independent packages to manage dependencies efficiently and allow for independent versioning.

    Key packages include:

    • sphinx-needs: The core Sphinx extension for managing requirements and specifications.
    • sphinx-mounts: An extension for mounting external source trees into a Sphinx build without copying or symlinking.
    • sphinx-codelinks: Provides fast source-code traceability by scanning source files for comment markers, converting them into needs, and linking documentation to exact source lines.
    • sphinx-test-reports: Converts test results (JUnit, ctest, googletest XML, and tox-envreport JSON) into Sphinx needs. It includes a test-reports command to generate a needs.json without running a full Sphinx build.
  8. Relationship between sphinx-mounts and the useblocks ecosystem

    master

    sphinx-mounts is part of the useblocks documentation tooling ecosystem. Most tools in this ecosystem use a shared ubproject.toml convention for configuration:

    ToolConfiguration Table in ubproject.tomlPurpose
    sphinx-mounts[[source.mounts]]Mounts external sources in place.
    Sphinx-Needs[needs]Requirements management and traceability.
    sphinx-codelinks[codelinks]Bidirectional source-to-doc traceability.
    ubCodeN/ALanguage server for validation and cross-references.

    Related specialized tools:

    • bazel-drives-sphinx: A heavier Bazel-driven companion to sphinx-mounts.
    • needs-config-writer: Bridges dynamic Python/Bazel configuration with the static ubproject.toml used by sphinx-mounts and ubCode.
    • sphinx-collections: A more general alternative for assembling content (supports copy, symlink, git clone, etc.) if you need more than just in-place reading.
  9. Use the Sphinx-Needs Python API modules

    master

    The Sphinx-Needs API is organized into several functional modules. When building extensions or custom tools, you will interact with these core areas:

    • sphinx_needs.api.configuration: Handles the injection of extra configuration.
    • sphinx_needs.api.need: The primary interface for defining and managing needs.
    • sphinx_needs.exceptions: Contains custom exception classes for error handling within the extension.
    • sphinx_needs.need_item: Provides data structures for individual needs, links, and parts (e.g., NeedItem, NeedLink, NeedPartItem).
    • sphinx_needs.data: Defines data types and protocols used throughout the system (e.g., NeedsInfoType, NeedsPartType).
    • sphinx_needs.views: Provides view objects used by filters. Warning: Do not instantiate these classes directly; they are intended to be returned by functions or injected into filters.
    • sphinx_needs.needs_schema & sphinx_needs.schema.config: Define the schema and field types for needs, including support for literal values, links, and specific field types (String, Boolean, Integer, etc.).
  10. What is sphinx-mounts and when to use it

    master

    Overview

    sphinx-mounts is a Sphinx extension designed to bridge the gap between modern build systems (like Bazel) and IDE-based Docs-as-Code workflows. It allows Sphinx to read documentation files (RST or Markdown) directly from their original filesystem locations without copying, symlinking, or staging them into the Sphinx srcdir.

    Key Use Cases

    • Zero-copy integration: When documentation is generated by an external build system (e.g., Bazel, Make) and you want Sphinx to access it in place.
    • IDE Support: When you need IDE extensions (like ubCode) to provide live feedback (cross-reference highlighting, linting, and previews) for files that live outside the standard Sphinx source tree.
    • Variant Management: To act as a Sphinx-side reader for the variant_sources key in ubproject.toml, allowing sphinx-build to narrow its document set per variant.

    Comparison: sphinx-mounts vs. sphinx-collections

    Aspectsphinx-collectionssphinx-mounts
    Core StrategyGeneric/Driver-based: Sphinx fetches or generates content (via git, copy, jinja, etc.) and writes it to _collections/ inside srcdir.Focused/Zero-copy: Content already exists at a known path; Sphinx reads it in place without materialization.
    On-disk location<srcdir>/_collections/<name>/Original filesystem path
    Configurationcollections dict in conf.py[[source.mounts]] array in ubproject.toml
    IDE ExperienceEditor sees files only after a build; contents may not be in VCS.Editor sees original files directly via the shared ubproject.toml contract.
    Best FitWhen Sphinx needs to pull content from heterogeneous sources (URLs, Git, templates).When a build system already provides files and you want to avoid staging/duplication.
  11. Extend Sphinx-Needs with custom need-types and filters

    master

    Sphinx-Needs provides an open API designed for other Sphinx extensions to interact with the needs ecosystem. Developers can use this API to:

    1. Define new need-types: Register custom requirement types that integrate with the Sphinx build process.
    2. Create needs: Programmatically generate or manipulate needs.
    3. Utilize filtering: Leverage the built-in filtering capabilities to query and display specific subsets of needs.

    Note: While the API allows for the injection of extra configuration, it does not support the removal of existing need types to ensure the final configuration remains transparent to Sphinx project authors.