Skip to content

Commit e69009c

Browse files
committed
link impl and test suits/files
1 parent 4d867c0 commit e69009c

File tree

17 files changed

+55
-5
lines changed

17 files changed

+55
-5
lines changed

docs/source/components/features.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Features
3030
.. feature:: Discover Source Code Files
3131
:id: FE_DISCOVERY
3232

33-
Discover source code files in a specified root directory. The root directory shall be configurable.
33+
Discover source code files in a specified root directory.
34+
The root directory shall be configurable.
3435

3536
.. feature:: C Language Support
3637
:id: FE_C_SUPPORT

docs/source/development/traceability.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ Testing
1212
-------
1313

1414
.. src-trace::
15-
:project: sphinx_codelinks
16-
:directory: tests
15+
:project: tests

docs/src_trace.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,35 @@ needs_fields = [
6161
{ "name" = "links", "type" = "list[str]", "default" = [
6262
] },
6363
]
64+
65+
# Configuration for tests project
66+
[codelinks.projects.tests]
67+
remote_url_pattern = "https://github.com/useblocks/sphinx-codelinks/blob/{commit}/{path}#L{line}"
68+
69+
[codelinks.projects.tests.source_discover]
70+
src_dir = "../tests"
71+
include = ["**/*.py"]
72+
exclude = [
73+
"**/__pycache__/**",
74+
"**/data/**",
75+
"**/doc_test/**",
76+
"**/__snapshots__/**",
77+
]
78+
comment_type = "python"
79+
gitignore = true
80+
81+
[codelinks.projects.tests.analyse]
82+
get_need_id_refs = false
83+
get_oneline_needs = true
84+
comment_type = "python"
85+
86+
[codelinks.projects.tests.analyse.oneline_comment_style]
87+
start_sequence = "@"
88+
field_split_char = ","
89+
needs_fields = [
90+
{ "name" = "title", "type" = "str" },
91+
{ "name" = "id", "type" = "str" },
92+
{ "name" = "type", "type" = "str", "default" = "test" },
93+
{ "name" = "links", "type" = "list[str]", "default" = [
94+
] },
95+
]

docs/ubproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ style = "node"
3737
[[needs.types]]
3838
directive = "test"
3939
title = "Test"
40-
prefix = "T_"
40+
prefix = "TEST_"
4141
color = "#DarkTurquoise"
4242
style = "node"
4343

src/sphinx_codelinks/analyse/analyse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def extract_marker(
127127
yield marker, need_ids, row_offset, start_column, end_column
128128
row_offset += 1
129129

130+
# @Extract need ID references from code comments, IMPL_LNK_1, impl, [FE_LNK]
130131
def extract_anchors(
131132
self,
132133
text: str,
@@ -211,6 +212,7 @@ def extract_oneline_need(
211212
yield resolved, row_offset
212213
row_offset += 1
213214

215+
# @Extract one-line traceability needs from comments, IMPL_ONE_1, impl, [FE_DEF, FE_CMT]
214216
def extract_oneline_needs(
215217
self,
216218
text: str,
@@ -258,6 +260,7 @@ def extract_oneline_needs(
258260
)
259261
return oneline_needs
260262

263+
# @Extract marked reStructuredText blocks from comments, IMPL_MRST_1, impl, [FE_RST_EXTRACTION]
261264
def extract_marked_rst(
262265
self,
263266
text: str,

src/sphinx_codelinks/analyse/oneline_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class OnelineParserInvalidWarning:
3131
msg: str
3232

3333

34+
# @One-line comment parser for traceability markers, IMPL_OLP_1, impl, [FE_DEF, FE_CMT]
3435
def oneline_parser( # noqa: PLR0912, PLR0911 # handel warnings
3536
oneline: str, oneline_config: OneLineCommentStyle
3637
) -> dict[str, str | list[str] | int] | OnelineParserInvalidWarning | None:

src/sphinx_codelinks/analyse/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def is_text_file(filepath: Path, sample_size: int = 2048) -> bool:
6464
return False
6565

6666

67+
# @Tree-sitter parser initialization for multiple languages, IMPL_LANG_1, impl, [FE_C_SUPPORT, FE_CPP, FE_PY, FE_YAML]
6768
def init_tree_sitter(comment_type: CommentType) -> tuple[Parser, Query]:
6869
if comment_type == CommentType.cpp:
6970
import tree_sitter_cpp # noqa: PLC0415
@@ -100,6 +101,7 @@ def read_callable_byte_offset(byte_offset: int, _: Point) -> ByteString:
100101
return read_callable_byte_offset
101102

102103

104+
# @Comment extraction from source code using tree-sitter, IMPL_EXTR_1, impl, [FE_DEF]
103105
def extract_comments(
104106
src_string: ByteString, parser: Parser, query: Query
105107
) -> list[TreeSitterNode] | None:
@@ -335,6 +337,7 @@ class ExtractedRstType(TypedDict):
335337
end_idx: int
336338

337339

340+
# @Extract reStructuredText blocks embedded in comments, IMPL_RST_1, impl, [FE_RST_EXTRACTION]
338341
def extract_rst(
339342
text: str, start_marker: str, end_marker: str
340343
) -> ExtractedRstType | None:

src/sphinx_codelinks/cmd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def analyse(
9090
] = None,
9191
) -> None:
9292
"""Analyse marked content in source code."""
93+
# @CLI command to analyse source code and extract traceability markers, IMPL_CLI_ANALYZE, impl, [FE_CLI_ANALYZE]
9394

9495
data: CodeLinksConfigType = load_config_from_toml(config)
9596

@@ -183,6 +184,7 @@ def discover(
183184
help="Glob patterns to be included.",
184185
),
185186
] = [], # noqa: B006 # to show the default value on CLI
187+
# @CLI command to discover source files recursively with gitignore support, IMPL_CLI_DISCOVER, impl, [FE_CLI_DISCOVER]
186188
gitignore: Annotated[
187189
bool,
188190
typer.Option(
@@ -234,6 +236,7 @@ def write_rst( # noqa: PLR0913 # for CLI, so it takes as many as it requires
234236
resolve_path=True,
235237
),
236238
],
239+
# @CLI command to generate needextend RST file from extracted markers, IMPL_CLI_WRITE, impl, [FE_CLI_WRITE]
237240
outpath: Annotated[
238241
Path,
239242
typer.Option(

src/sphinx_codelinks/source_discover/source_discover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515

16-
# @Source discovery, IMPL_DC_1, impl, [FE_DEF]
16+
# @Source code file discovery with gitignore support, IMPL_DISC_1, impl, [FE_DISCOVERY, FE_CLI_DISCOVER]
1717
class SourceDiscover:
1818
def __init__(self, src_discover_config: SourceDiscoverConfig):
1919
self.src_discover_config = src_discover_config

tests/test_analyse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# @Test suite for source code analysis and marker extraction, TEST_ANA_1, test, [IMPL_LNK_1, IMPL_ONE_1, IMPL_MRST_1]
12
import json
23
from pathlib import Path
34

0 commit comments

Comments
 (0)