You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
``CodeLinks`` is a Sphinx extension that provides the ``src-trace`` directive to establish traceability between source code and :external+needs:doc:`Sphinx-Needs <index>` items.
4
+
``CodeLinks`` is a versatile utility that enables fast source code tracing and connects it to
5
+
the :external+needs:doc:`Sphinx-Needs <index>` ecosystem.
5
6
6
-
At its core, ``CodeLinks`` uses a powerful ``Analyse`` to parse source code comments and extract valuable information. The ``Analyse`` can identify and extract three distinct types of content:
7
+
It has multiple components:
7
8
8
-
- **One-line need definitions**: Create new Sphinx-Needs directly from a single, :ref:`customized comment line <oneline>` in your source code.
9
+
- source code analyzer for multiple programming languages and comment styles
10
+
- generator for various output formats that contain the extracted markers or needs
11
+
- Sphinx extension that integrates ``CodeLinks`` with Sphinx-Needs
12
+
- CLI application to drive the analysis and generation process
13
+
14
+
The configuration for ``CodeLinks`` is done via a TOML file, which can be used
15
+
for both the :ref:`Sphinx extension <configuration>` and the :ref:`CLI application <cli>`.
16
+
17
+
The configuration determines how markers and languages are ingested and how the Sphinx extension should behave.
18
+
19
+
At its core, ``CodeLinks`` parses the source code structure and extracts source markers.
20
+
Source markers can be special comments or language-specific constructs like docstrings for Python.
21
+
22
+
``CodeLinks`` supports 3 distinct marker types:
23
+
24
+
- :ref:`One-line need definitions <oneline>`: Create new Sphinx-Needs directly from a single customized comment line
25
+
in your source code.
9
26
- **Need ID references**: Link code to existing need items without creating new ones, perfect for tracing implementations to requirements.
10
27
- **Marked RST text**: Extract blocks of reStructuredText embedded within comments, allowing you to include rich documentation with associated metadata right next to your code.
11
28
12
-
``src-trace`` directive then consumes ``One-line need definitions`` to generate traceability between source code and your documentation.
29
+
When used in a Sphinx context, a new :ref:`directive` creates items at the location where it is placed (for a subset
30
+
of the analyzed files/folders).
31
+
32
+
For use cases where ``CodeLinks`` should not integrate with Sphinx, but rather generate output files, the
33
+
:ref:`cli` can be used. Currently it can write out ``needextend`` directives for the need ID reference comment style.
34
+
Other output files are planned such as full need items as RST or needs.json.
13
35
14
-
The ``Analyse``, along with the ``SourceDiscovery`` module, also provides both a **Python API** for extensibility and a **CLI** for integration into CI/CD pipelines.
36
+
The availability of most commands as :ref:`cli` also helps integrate ``CodeLinks`` into build systems and CI/CD pipelines.
37
+
Focus is put on performance, portability and caching of processing steps.
The ``Analyse`` is a :ref:`CLI tool <cli>` that also provides an API for programmatic use. Its primary function is to extract specific, marked content from comments within source code files.
3
+
Source Analyse
4
+
==============
5
5
6
-
It can extract three types of content:
6
+
The **Source Analyse** module is a powerful component of **Sphinx-CodeLinks** that extracts documentation-related content from source code comments. It provides both CLI and API interfaces for flexible integration into documentation workflows.
7
7
8
-
- Sphinx-Needs ID References
9
-
- Oneline needs (see :ref:`OneLineCommentStyle <oneline>`)
10
-
- Marked reStructuredText (RST) blocks
8
+
**Key Capabilities:**
11
9
12
-
Configuration
13
-
-------------
10
+
- Extract **Sphinx-Needs** ID references from source code comments
11
+
- Process custom one-line comment patterns for rapid documentation
12
+
- Extract marked reStructuredText (RST) blocks embedded in comments
13
+
- Generate structured JSON output for further processing
14
+
- Support for multiple programming language comment styles
14
15
15
-
The ``Analyse`` is configured using a ``toml`` file. The examples throughout this document are based on the following configuration:
Source Analyse works by parsing source code files and identifying specially marked comments that contain documentation information. This enables developers to embed documentation directly in their source code while maintaining clean separation between code and documentation.
20
20
21
-
This configuration instructs the analyse to extract ``Sphinx-Needs ID Refs`` and ``Marked rst text`` using the defined markers.
21
+
The module supports three primary extraction modes:
22
22
23
-
Sphinx-Needs ID Refs
24
-
--------------------
23
+
1. **Sphinx-Needs ID References** - Links between code and requirements/specifications
24
+
2. **One-line Needs** - Simplified syntax for creating documentation needs
25
+
3. **Marked RST Blocks** - Full reStructuredText content embedded in comments
26
+
27
+
Supported Content Types
28
+
-----------------------
29
+
30
+
Sphinx-Needs ID References
31
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
32
+
33
+
Extract references to **Sphinx-Needs** items directly from source code comments, enabling traceability between code implementations and requirements.
34
+
35
+
One-line Needs
36
+
~~~~~~~~~~~~~~
37
+
38
+
Use simplified comment patterns to define **Sphinx-Needs** items without complex RST syntax. See :ref:`OneLineCommentStyle <oneline>` for detailed information.
39
+
40
+
Marked RST Blocks
41
+
~~~~~~~~~~~~~~~~~
42
+
43
+
Embed complete reStructuredText content within source code comments for rich documentation that can be extracted and processed.
44
+
45
+
Limitations
46
+
-----------
47
+
48
+
**Current Limitations:**
49
+
50
+
- **Language Support**: Only C/C++ (``//``, ``/* */``) and Python (``#``) comment styles are supported
51
+
- **Single Comment Style**: Each analysis run processes only one comment style at a time
52
+
53
+
Extraction Examples
54
+
-------------------
55
+
56
+
The following examples are configured with :ref:`the analyse configuration <analyse_config>`,
57
+
58
+
Sphinx-Needs ID References
59
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
25
60
26
61
Below is an example of a C++ source file containing need ID references and the corresponding JSON output from the analyse.
0 commit comments