Skip to content

Commit

Permalink
docs: migrate several links to new @relation syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Nov 6, 2024
1 parent 9a2e28a commit bc58e6e
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 38 deletions.
24 changes: 0 additions & 24 deletions docs/strictdoc_21_L2_StrictDoc_Requirements.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ STATEMENT: >>>
StrictDoc's data model shall support modeling requirements.
<<<
RELATIONS:
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/backend/sdoc/models/node.py
- TYPE: Parent
VALUE: SDOC-SSS-4

Expand Down Expand Up @@ -119,9 +116,6 @@ These fields are the most typical fields found in requirement documents.
RELATIONS:
- TYPE: Parent
VALUE: SDOC-SSS-61
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/backend/sdoc/models/document_grammar.py

[REQUIREMENT]
MID: f94419a390f2403daa3c4cd0e96f6cb6
Expand Down Expand Up @@ -168,9 +162,6 @@ RATIONALE: >>>
RELATIONS:
- TYPE: Parent
VALUE: SDOC-SSS-51
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/backend/sdoc/models/section.py

[REQUIREMENT]
MID: 899d2f68749b4be1a3124fe4d01de1aa
Expand All @@ -184,9 +175,6 @@ RATIONALE: >>>
Documentation comprises normative components, such as uniquely identifiable elements like requirements or design items, and non-normative components, including introductory text, overview chapters, and other content. The non-normative parts help provide a general understanding for the reader but do not contribute to traceability information. StrictDoc's free text is designed to store this type of non-normative information in SDoc documents.
<<<
RELATIONS:
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/backend/sdoc/models/free_text.py
- TYPE: Parent
VALUE: SDOC-SSS-3

Expand All @@ -209,12 +197,6 @@ RELATIONS:
VALUE: SDOC-SSS-52
- TYPE: Parent
VALUE: DO178-4
- TYPE: File
VALUE: strictdoc/backend/sdoc/models/document_from_file.py
- TYPE: File
VALUE: strictdoc/backend/sdoc/models/document.py
- TYPE: File
VALUE: strictdoc/core/traceability_index_builder.py

[REQUIREMENT]
MID: fad4cf5dcf4d40518c7c9826fd6bd18a
Expand Down Expand Up @@ -546,9 +528,6 @@ The requirement ensures that the Traceability Index takes of care of validating
RELATIONS:
- TYPE: Parent
VALUE: SDOC-SSS-89
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/core/traceability_index_builder.py
- TYPE: Parent
VALUE: SDOC-SSS-94

Expand All @@ -563,9 +542,6 @@ The Traceability Index shall detect cycles between requirements.
RELATIONS:
- TYPE: Parent
VALUE: SDOC-SSS-47
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/core/traceability_index_builder.py
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/core/tree_cycle_detector.py
Expand Down
1 change: 1 addition & 0 deletions strictdoc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ features = [
# "STANDALONE_DOCUMENT_SCREEN",
"TRACEABILITY_MATRIX_SCREEN",
"REQUIREMENT_TO_SOURCE_TRACEABILITY",
"SOURCE_FILE_LANGUAGE_PARSERS",
"HTML2PDF",
"DIFF",
"NESTOR",
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/document.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
@relation(SDOC-SRS-109, scope=file)
"""

# mypy: disable-error-code="union-attr,type-arg"
from typing import Generator, List, Optional

Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/document_from_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
@relation(SDOC-SRS-109, scope=file)
"""

# mypy: disable-error-code="no-untyped-def,type-arg"
from typing import List, Optional

Expand Down
4 changes: 2 additions & 2 deletions strictdoc/backend/sdoc/models/document_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def create_default(parent) -> "DocumentGrammar":
DocumentGrammar.create_default_text_element()
)

# @sdoc[SDOC-SRS-132]
# @relation(SDOC-SRS-132, scope=range_start)
fields: List[
Union[
GrammarElementFieldString,
Expand Down Expand Up @@ -270,7 +270,7 @@ def create_default(parent) -> "DocumentGrammar":
requirement_element = GrammarElement(
parent=None, tag="REQUIREMENT", fields=fields, relations=[]
)
# @sdoc[/SDOC-SRS-132]
# @relation(SDOC-SRS-132, scope=range_end)

requirement_element.relations = create_default_relations(
requirement_element
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/free_text.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
@relation(SDOC-SRS-135, scope=file)
"""

from typing import Any, List, Optional

from strictdoc.backend.sdoc.models.anchor import Anchor
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
@relation(SDOC-SRS-26, scope=file)
"""

# mypy: disable-error-code="union-attr"
from collections import OrderedDict
from typing import Any, Generator, List, Optional, Tuple, Union
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/backend/sdoc/models/section.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
@relation(SDOC-SRS-99, scope=file)
"""

# mypy: disable-error-code="attr-defined,no-untyped-call,no-untyped-def,union-attr"
from typing import List, Optional, Union

Expand Down
2 changes: 1 addition & 1 deletion strictdoc/backend/sdoc_source_code/marker_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def parse(
range_marker.ng_source_column_begin = first_requirement_column
range_marker.ng_range_line_begin = line_start
range_marker.ng_range_line_end = line_end
range_marker.ng_is_language_parsed = True
range_marker.ng_new_relation_keyword = True
markers.append(range_marker)
elif marker_type == "line":
line_marker = LineMarker(None, requirements)
Expand Down
3 changes: 2 additions & 1 deletion strictdoc/backend/sdoc_source_code/models/range_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
else:
assert scope in ("range_start", "range_end")
self.begin_or_end = "[" if scope == "range_start" else "[/"
self.ng_new_relation_keyword = True

self.reqs_objs: List[Req] = reqs_objs
self.reqs: List[str] = list(map(lambda req: req.uid, reqs_objs))
Expand All @@ -44,7 +45,7 @@ def __init__(
self.ng_range_line_end: Optional[int] = None

self.ng_is_nodoc = "nosdoc" in self.reqs
self.ng_is_language_parsed = False
self.ng_new_relation_keyword = False

def is_begin(self) -> bool:
return self.begin_or_end == "["
Expand Down
4 changes: 4 additions & 0 deletions strictdoc/core/file_traceability_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def marker_comparator(marker):

markers_.sort(key=marker_comparator)

# Sort by keys alphabetically.
for paths_ in self.map_reqs_uids_to_paths.values():
paths_.sort()

def create_requirement(self, requirement: SDocNode) -> None:
assert requirement.reserved_uid is not None

Expand Down
12 changes: 6 additions & 6 deletions strictdoc/core/traceability_index_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def create_from_document_tree(
)

if node.reserved_uid is not None:
# @sdoc[SDOC-SRS-29]
# @relation(SDOC-SRS-29, scope=range_start)
if traceability_index.graph_database.has_link(
link_type=GraphLinkType.UID_TO_NODE,
lhs_node=node.reserved_uid,
Expand Down Expand Up @@ -455,7 +455,7 @@ def create_from_document_tree(
f'and "{document.title}".'
)
sys.exit(1)
# @sdoc[/SDOC-SRS-29]
# @relation(SDOC-SRS-29, scope=range_end)

traceability_index.graph_database.create_link(
link_type=GraphLinkType.UID_TO_NODE,
Expand Down Expand Up @@ -687,7 +687,7 @@ def create_from_document_tree(
if requirement.reserved_uid is None:
continue

# @sdoc[SDOC-SRS-30] # noqa: ERA001
# @relation(SDOC-SRS-30, scope=range_start)
# Detect cycles
parents_cycle_detector.check_node(
requirement.reserved_uid,
Expand All @@ -703,15 +703,15 @@ def create_from_document_tree(
lhs_node=requirement_id_,
).get_child_uids(),
)
# @sdoc[/SDOC-SRS-30]
# @relation(SDOC-SRS-30, scope=range_end)

map_documents_by_input_rel_path: Dict[str, SDocDocument] = {}
for document_ in document_tree.document_list:
map_documents_by_input_rel_path[
document_.meta.input_doc_full_path
] = document_

# @sdoc[SDOC-SRS-109]
# @relation(SDOC-SRS-109, scope=range_start)
unique_document_from_file_occurences: Set[str] = set()
for document_ in document_tree.document_list:
document_from_file_: DocumentFromFile
Expand Down Expand Up @@ -764,7 +764,7 @@ def create_from_document_tree(
resolved_document
)

# @sdoc[/SDOC-SRS-109]
# @relation(SDOC-SRS-109, scope=range_end)

return traceability_index

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ def get_pygmented_source_lines(
closing_bracket_index = (
source_line.index("]")
if isinstance(marker, RangeMarker)
and not marker.ng_is_language_parsed
and not marker.ng_new_relation_keyword
else source_line.index(", scope")
if isinstance(marker, FunctionRangeMarker)
or (
isinstance(marker, RangeMarker)
and marker.ng_is_language_parsed
and marker.ng_new_relation_keyword
)
else source_line.index(")")
if isinstance(marker, LineMarker)
Expand Down
7 changes: 5 additions & 2 deletions strictdoc/helpers/ordered_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def __len__(self) -> int:
def __iter__(self) -> t.Iterator[T]:
return self._d.__iter__()

def __str__(self):
def __str__(self) -> str:
return f"{{{', '.join(str(i) for i in self)}}}"

def __repr__(self):
def __repr__(self) -> str:
return f"<OrderedSet {self}>"

def sort(self) -> None:
self._d = dict(sorted(self._d.items()))

0 comments on commit bc58e6e

Please sign in to comment.