Skip to content

Commit

Permalink
backend/sdoc: Document: remove .free_texts
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislaw committed Jun 12, 2024
1 parent 275a332 commit a89ec15
Show file tree
Hide file tree
Showing 12 changed files with 8 additions and 419 deletions.
113 changes: 1 addition & 112 deletions strictdoc/backend/reqif/p01_sdoc/sdoc_to_reqif_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
GrammarElementFieldString,
ReferenceType,
)
from strictdoc.backend.sdoc.writer import SDWriter
from strictdoc.core.document_iterator import DocumentCachingIterator
from strictdoc.core.document_tree import DocumentTree
from strictdoc.helpers.cast import assert_cast
Expand Down Expand Up @@ -234,29 +233,7 @@ def convert_document_tree(
)

current_hierarchy = root_hierarchy
if len(document.free_texts) > 0:
# fmt: off
document_free_text_spec_object = (
P01_SDocToReqIFObjectConverter
._convert_document_free_text_to_spec_object(
document,
context=context,
)
)
# fmt: on
spec_objects.append(document_free_text_spec_object)
hierarchy = ReqIFSpecHierarchy(
xml_node=None,
is_self_closed=False,
identifier=generate_unique_identifier("SPEC-HIERARCHY"),
last_change=None,
long_name=None,
spec_object=document_free_text_spec_object.identifier,
children=[],
ref_then_children_order=True,
level=document.ng_level + 1,
)
current_hierarchy.add_child(hierarchy)

# FIXME: ReqIF must export complete documents including fragments.
for node in document_iterator.all_content(
print_fragments=False, print_fragments_from_files=False
Expand Down Expand Up @@ -421,44 +398,6 @@ def convert_document_tree(
)
return reqif_bundle

@classmethod
def _convert_document_free_text_to_spec_object(
cls,
document: SDocDocument,
context: P01_SDocToReqIFBuildContext,
) -> ReqIFSpecObject:
assert isinstance(document, SDocDocument)
assert len(document.free_texts) > 0
attributes = []
free_text_value = (
SDWriter.print_free_text_content(document.free_texts[0])
).rstrip()
if context.multiline_is_xhtml:
attribute_type = SpecObjectAttributeType.XHTML
else:
attribute_type = SpecObjectAttributeType.STRING
free_text_value = escape(free_text_value)

free_text_attribute = SpecObjectAttribute(
xml_node=None,
attribute_type=attribute_type,
definition_ref=ReqIFChapterField.TEXT,
value=free_text_value,
)
attributes.append(free_text_attribute)
spec_object = ReqIFSpecObject(
xml_node=None,
description=None,
identifier=generate_unique_identifier("DOCUMENT_FREETEXT"),
last_change=None,
long_name=None,
spec_object_type=context.map_grammar_node_tags_to_spec_object_type[
document
]["FREETEXT"].identifier,
attributes=attributes,
)
return spec_object

@classmethod
def _convert_section_to_spec_object(
cls,
Expand All @@ -475,23 +414,6 @@ def _convert_section_to_spec_object(
value=section.title,
)
attributes.append(title_attribute)
if len(section.free_texts) > 0:
free_text_value = (
SDWriter.print_free_text_content(section.free_texts[0])
).rstrip()
if context.multiline_is_xhtml:
attribute_type = SpecObjectAttributeType.XHTML
else:
attribute_type = SpecObjectAttributeType.STRING
free_text_value = escape(free_text_value)

free_text_attribute = SpecObjectAttribute(
xml_node=None,
attribute_type=attribute_type,
definition_ref=ReqIFChapterField.TEXT,
value=free_text_value,
)
attributes.append(free_text_attribute)

"""
If MIDs is enabled and this section has an MID, use it for
Expand Down Expand Up @@ -742,15 +664,6 @@ def _convert_document_grammar_to_spec_types(
"SECTION"
] = section_spec_type
spec_object_types.append(section_spec_type)
free_text_spec_type = (
P01_SDocToReqIFObjectConverter._create_free_text_spec_object_type(
context
)
)
context.map_grammar_node_tags_to_spec_object_type[grammar.parent][
"FREETEXT"
] = free_text_spec_type
spec_object_types.append(free_text_spec_type)

return spec_object_types

Expand All @@ -774,27 +687,3 @@ def _create_section_spec_object_type(
attribute_definitions=attribute_definitions,
)
return spec_object_type

@classmethod
def _create_free_text_spec_object_type(
cls,
context: P01_SDocToReqIFBuildContext,
):
attribute_definitions = []
chapter_name_attribute = SpecAttributeDefinition.create(
attribute_type=SpecObjectAttributeType.XHTML
if context.multiline_is_xhtml
else SpecObjectAttributeType.STRING,
identifier=ReqIFChapterField.TEXT,
datatype_definition=StrictDocReqIFTypes.MULTI_LINE_STRING.value,
long_name=ReqIFChapterField.TEXT,
)
attribute_definitions.append(chapter_name_attribute)

spec_object_type_identifier = "FREE_TEXT_" + uuid.uuid4().hex
spec_object_type = ReqIFSpecObjectType.create(
identifier=spec_object_type_identifier,
long_name="FREETEXT",
attribute_definitions=attribute_definitions,
)
return spec_object_type
7 changes: 0 additions & 7 deletions strictdoc/backend/sdoc/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(
view if view is not None else DocumentView.create_default(self)
)
self.grammar: Optional[DocumentGrammar] = grammar
self.free_texts: List[FreeText] = free_texts
self.section_contents: List = section_contents

# FIXME: Plain list of all fragments found in the document.
Expand Down Expand Up @@ -173,9 +172,3 @@ def enumerate_custom_content_field_titles(
yield from self.grammar.elements[
0
].enumerate_custom_content_field_titles()

def set_freetext(self, freetext: Optional[FreeText]) -> None:
if freetext is None:
self.free_texts = []
return
self.free_texts = [freetext]
4 changes: 0 additions & 4 deletions strictdoc/backend/sdoc/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ def write_with_fragments(
if element_relation.relation_role is not None:
output += f" ROLE: {element_relation.relation_role}\n"

for free_text in document.free_texts:
output += "\n"
output += self._print_free_text(free_text)

output += "\n"

output += self._print_node(document, document, document_iterator)
Expand Down
35 changes: 0 additions & 35 deletions strictdoc/core/traceability_index_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,6 @@ def create_from_document_tree(
rhs_node=document_tags,
)

for free_text in document.free_texts:
for part in free_text.parts:
if isinstance(part, Anchor):
graph_database.create_link(
link_type=GraphLinkType.MID_TO_NODE,
lhs_node=part.mid,
rhs_node=part,
)
graph_database.create_link(
link_type=GraphLinkType.UID_TO_NODE,
lhs_node=part.value,
rhs_node=part,
)

document_iterator = DocumentCachingIterator(document)
d_01_document_iterators[document] = document_iterator

Expand Down Expand Up @@ -485,27 +471,6 @@ def create_from_document_tree(
# Now iterate over the requirements again to build an in-depth map of
# parents and children.
for document in document_tree.document_list:
if len(document.free_texts) > 0:
for part in document.free_texts[0].parts:
if isinstance(part, InlineLink):
# FIXME: Ensure that the section UIDs are written to UID_TO_NODE,
# remove the second check of UID_TO_REQUIREMENT_CONNECTIONS.
if not traceability_index.graph_database.has_link(
link_type=GraphLinkType.UID_TO_REQUIREMENT_CONNECTIONS,
lhs_node=part.link,
) and not graph_database.has_link(
link_type=GraphLinkType.UID_TO_NODE,
lhs_node=part.link,
):
raise StrictDocException(
"DocumentIndex: "
"the inline link references an "
"object with an UID "
"that does not exist: "
f"{part.link}."
)
traceability_index.create_inline_link(part)

document_iterator = d_01_document_iterators[document]

for node in document_iterator.all_content(
Expand Down
3 changes: 0 additions & 3 deletions strictdoc/export/json/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ def _write_document(cls, document: SDocDocument) -> Dict:

document_dict[JSONKey.GRAMMAR]["ELEMENTS"].append(element_dict)

for free_text in document.free_texts:
document_dict["FREETEXT"] = cls._write_free_text_content(free_text)

node_dict = JSONGenerator._write_node(document, document, ())
document_dict[JSONKey.NODES] = node_dict[JSONKey.NODES]

Expand Down
3 changes: 0 additions & 3 deletions strictdoc/export/rst/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ def write(self, document: SDocDocument, single_document: bool) -> str:
document.title, 0, reference_uid=document_uid
)

for free_text in document.free_texts:
output += self._print_free_text(free_text)

for content_node in document_iterator.all_content():
if isinstance(content_node, SDocSection):
output += self._print_rst_header(
Expand Down
36 changes: 0 additions & 36 deletions strictdoc/git/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,17 @@ def __init__(
rhs_document: Optional[SDocDocument],
uid_modified: bool,
title_modified: bool,
free_text_modified: bool,
lhs_colored_title_diff: Optional[str],
rhs_colored_title_diff: Optional[str],
lhs_colored_free_text_diff: Optional[str],
rhs_colored_free_text_diff: Optional[str],
):
assert lhs_document is not None or rhs_document is not None
if matched_uid is not None:
assert len(matched_uid) > 0
self.matched_uid: Optional[str] = matched_uid
self.uid_modified: bool = uid_modified
self.title_modified: bool = title_modified
self.free_text_modified: bool = free_text_modified
self.lhs_colored_title_diff: Optional[str] = lhs_colored_title_diff
self.rhs_colored_title_diff: Optional[str] = rhs_colored_title_diff
self.lhs_colored_free_text_diff: Optional[str] = (
lhs_colored_free_text_diff
)
self.rhs_colored_free_text_diff: Optional[str] = (
rhs_colored_free_text_diff
)

self.lhs_document: Optional[SDocDocument] = lhs_document
self.rhs_document: Optional[SDocDocument] = rhs_document
Expand All @@ -71,15 +61,6 @@ def get_colored_title_diff(self, side: str) -> Optional[str]:
return self.rhs_colored_title_diff
raise AssertionError(f"Must not reach here: {side}")

def get_colored_free_text_diff(self, side: str) -> Optional[str]:
if not self.free_text_modified:
return None
if side == "left":
return self.lhs_colored_free_text_diff
if side == "right":
return self.rhs_colored_free_text_diff
raise AssertionError(f"Must not reach here: {side}")


@auto_described
class SectionChange:
Expand All @@ -93,11 +74,8 @@ def __init__(
rhs_section: Optional[SDocSection],
uid_modified: bool,
title_modified: bool,
free_text_modified: bool,
lhs_colored_title_diff: Optional[str],
rhs_colored_title_diff: Optional[str],
lhs_colored_free_text_diff: Optional[str],
rhs_colored_free_text_diff: Optional[str],
):
assert lhs_section is not None or rhs_section is not None
if matched_uid is not None:
Expand All @@ -107,15 +85,8 @@ def __init__(
self.section_token: Optional[str] = section_token
self.uid_modified: bool = uid_modified
self.title_modified: bool = title_modified
self.free_text_modified: bool = free_text_modified
self.lhs_colored_title_diff: Optional[str] = lhs_colored_title_diff
self.rhs_colored_title_diff: Optional[str] = rhs_colored_title_diff
self.lhs_colored_free_text_diff: Optional[str] = (
lhs_colored_free_text_diff
)
self.rhs_colored_free_text_diff: Optional[str] = (
rhs_colored_free_text_diff
)

self.lhs_section: Optional[SDocSection] = lhs_section
self.rhs_section: Optional[SDocSection] = rhs_section
Expand Down Expand Up @@ -145,13 +116,6 @@ def get_colored_title_diff(self, side: str) -> Optional[str]:
return self.rhs_colored_title_diff
raise AssertionError(f"Must not reach here: {side}")

def get_colored_free_text_diff(self, side: str) -> Optional[str]:
if side == "left":
return self.lhs_colored_free_text_diff
if side == "right":
return self.rhs_colored_free_text_diff
raise AssertionError(f"Must not reach here: {side}")


@auto_described
class RequirementFieldChange:
Expand Down
Loading

0 comments on commit a89ec15

Please sign in to comment.