StrictDoc Documentation
strictdoc/backend/sdoc/models/model.py
Source file coverage
Path:
strictdoc/backend/sdoc/models/model.py
Lines:
199
Non-empty lines:
156
Non-empty lines covered with requirements:
156 / 156 (100.0%)
Functions:
25
Functions covered by requirements:
25 / 25 (100.0%)
1
"""
2
@relation(SDOC-SRS-18, scope=file)
3
"""
4
 
5
from abc import ABC, abstractmethod
6
from typing import Final, Generator, List, Optional, Union
7
 
8
from strictdoc.backend.sdoc.models.document_config import (
9
    DocumentConfig,
10
)
11
from strictdoc.backend.sdoc_source_code.models.source_file_info import (
12
    SourceFileTraceabilityInfo,
13
)
14
from strictdoc.core.document_meta import DocumentMeta
15
from strictdoc.helpers.mid import MID
16
 
17
 
18
class RequirementFieldName:
19
    MID = "MID"
20
    UID = "UID"
21
    PREFIX = "PREFIX"
22
    LEVEL = "LEVEL"
23
    STATUS = "STATUS"
24
    TAGS = "TAGS"
25
    TITLE = "TITLE"
26
 
27
    # {STATEMENT, DESCRIPTION, CONTENT} are aliases.
28
    # It is assumed that either field is provided for each node.
29
    STATEMENT = "STATEMENT"
30
    DESCRIPTION = "DESCRIPTION"
31
    CONTENT = "CONTENT"
32
 
33
    RATIONALE = "RATIONALE"
34
    COMMENT = "COMMENT"
35
 
36
    RESERVED_SINGLELINE_FIELDS: Final[frozenset[str]] = frozenset(
37
        (
38
            MID,
39
            UID,
40
            PREFIX,
41
            LEVEL,
42
            STATUS,
43
            TAGS,
44
            TITLE,
45
        )
46
    )
47
 
48
    RESERVED_NON_META_FIELDS: Final[frozenset[str]] = frozenset(
49
        (
50
            TITLE,
51
            STATEMENT,
52
            DESCRIPTION,
53
            CONTENT,
54
            COMMENT,
55
            RATIONALE,
56
        )
57
    )
58
 
59
 
60
class SDocNodeFieldIF(ABC):
61
    parent: "SDocNodeIF"
62
 
63
 
64
class SDocNodeIF(ABC):
65
    reserved_mid: MID
66
    mid_permanent: bool
67
    parent: Union["SDocNodeIF", "SDocDocumentIF"]
68
    node_type: str
69
    section_contents: List["SDocElementIF"]
70
    ng_level: Optional[int]
71
    ng_resolved_custom_level: Optional[str]
72
    ng_has_requirements: bool
73
    autogen: bool
74
 
75
    @property
76
    @abstractmethod
77
    def reserved_uid(self) -> Optional[str]:
78
        raise NotImplementedError
79
 
80
    @reserved_uid.setter
81
    @abstractmethod
82
    def reserved_uid(self, uid: Optional[str]) -> None:
83
        raise NotImplementedError
84
 
85
    @property
86
    def reserved_title(self) -> Optional[str]:
87
        raise NotImplementedError
88
 
89
    @abstractmethod
90
    def is_normative_node(self) -> bool:
91
        raise NotImplementedError
92
 
93
    @abstractmethod
94
    def is_text_node(self) -> bool:
95
        raise NotImplementedError
96
 
97
    @abstractmethod
98
    def get_debug_info(self) -> str:
99
        raise NotImplementedError
100
 
101
    @abstractmethod
102
    def get_document(self) -> Optional["SDocDocumentIF"]:
103
        raise NotImplementedError
104
 
105
    @abstractmethod
106
    def get_including_document(self) -> Optional["SDocDocumentIF"]:
107
        raise NotImplementedError
108
 
109
    @abstractmethod
110
    def get_parent_or_including_document(self) -> "SDocDocumentIF":
111
        raise NotImplementedError
112
 
113
    @abstractmethod
114
    def get_prefix(self) -> Optional[str]:
115
        raise NotImplementedError
116
 
117
 
118
class SDocGrammarIF:
119
    pass
120
 
121
 
122
class SDocDocumentIF(ABC):
123
    reserved_mid: MID
124
    mid_permanent: bool
125
    section_contents: List["SDocElementIF"]
126
    included_documents: List["SDocDocumentIF"]
127
    config: DocumentConfig
128
    grammar: Optional[SDocGrammarIF]
129
    meta: Optional[DocumentMeta]
130
    is_bundle_document: bool
131
    ng_level: Optional[int]
132
    ng_has_requirements: bool
133
    autogen: bool
134
 
135
    # FIXME: Get rid of @property everywhere.
136
    @property
137
    def reserved_uid(self) -> Optional[str]:
138
        raise NotImplementedError
139
 
140
    @abstractmethod
141
    def get_prefix(self) -> str:
142
        raise NotImplementedError
143
 
144
    @abstractmethod
145
    def get_debug_info(self) -> str:
146
        raise NotImplementedError
147
 
148
    @abstractmethod
149
    def iterate_included_documents_depth_first(
150
        self,
151
    ) -> Generator["SDocDocumentIF", None, None]:
152
        raise NotImplementedError
153
 
154
    def document_is_included(self) -> bool:
155
        raise NotImplementedError
156
 
157
    @abstractmethod
158
    def get_display_title(self, include_toc_number: bool = True) -> str:
159
        raise NotImplementedError
160
 
161
    @property
162
    def ng_resolved_custom_level(self) -> Optional[str]:
163
        raise NotImplementedError
164
 
165
 
166
class SDocDocumentFromFileIF(ABC):
167
    parent: Union[SDocDocumentIF, SDocNodeIF]
168
    ng_resolved_custom_level: Optional[str]
169
    autogen: bool
170
 
171
    @abstractmethod
172
    def iterate_nodes(
173
        self,
174
        element_type: Optional[str] = None,
175
    ) -> Generator[SDocNodeIF, None, None]:
176
        raise NotImplementedError
177
 
178
    @property
179
    def section_contents(self) -> List[SDocDocumentIF]:
180
        raise NotImplementedError
181
 
182
 
183
SDocElementIF = Union[
184
    SDocNodeIF,
185
    SDocDocumentIF,
186
    SDocDocumentFromFileIF,
187
]
188
 
189
 
190
SDocIteratedElementIF = Union[
191
    SDocNodeIF,
192
    SDocDocumentIF,
193
]
194
 
195
 
196
SDocExtendedElementIF = Union[
197
    SDocElementIF,
198
    SourceFileTraceabilityInfo,
199
]