Skip to content

[[NODE]] migration: extend project statistics and query syntax to support [[SECTION]] #2274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions strictdoc/backend/sdoc/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ def has_multiline_fields(self) -> bool:
return True
return False

def has_any_text_nodes(self) -> bool:
# The workaround: hasattr(...) makes mypy happy.
return any(
node_.__class__.__name__ == "SDocNode"
and hasattr(node_, "node_type")
and node_.node_type == "TEXT"
for node_ in self.section_contents
)

#
# Reserved fields
#
Expand Down
10 changes: 7 additions & 3 deletions strictdoc/core/query_engine/query_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def _evaluate(self, node: SDocElementIF, expression: Any) -> bool:
isinstance(node, SDocNode) and node.node_type == "REQUIREMENT"
)
if isinstance(expression, NodeIsSectionExpression):
return isinstance(node, SDocSection)
return (
isinstance(node, SDocNode) and node.node_type == "SECTION"
) or isinstance(node, SDocSection)
if isinstance(expression, NodeIsRootExpression):
if isinstance(node, SDocNode):
return node.is_root
Expand Down Expand Up @@ -295,10 +297,12 @@ def _evaluate_node_contains(
raise NotImplementedError # pragma: no cover

def _evaluate_node_contains_any_text(self, node: SDocElementIF) -> bool:
if not isinstance(node, SDocSection):
if not isinstance(node, SDocSection) and not (
isinstance(node, SDocNode) and node.node_type == "SECTION"
):
raise TypeError(
f"node.contains_any_text can be only called on "
f"Section objects, got: {node.__class__.__name__}. To fix "
f"SECTION objects, got: {node.__class__.__name__}. To fix "
f"the error, prepend your query with node.is_section."
)
return node.has_any_text_nodes()
6 changes: 1 addition & 5 deletions strictdoc/core/traceability_index_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import glob
import os
import sys
from time import sleep
from typing import Dict, Iterator, List, Optional, Set, Union

from textx import TextXSyntaxError
Expand Down Expand Up @@ -399,12 +398,9 @@ def print_line(text: str):
"document grammar. "
"See the migration guide for more details:\n"
"https://strictdoc.readthedocs.io/en/latest/latest/docs/strictdoc_01_user_guide.html#SECTION-UG-NODE-MIGRATION\n"
"This warning will become an error in 2025 Q3. "
"Sleeping for 5 seconds..."
"This warning will become an error in 2025 Q3."
)

sleep(5)

if isinstance(node, SDocNode):
try:
SDocValidator.validate_node(
Expand Down
4 changes: 3 additions & 1 deletion strictdoc/export/html/generators/project_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def export(
for node in document_iterator.all_content(
print_fragments=False, print_fragments_from_files=False
):
if isinstance(node, SDocSection):
if isinstance(node, SDocSection) or (
isinstance(node, SDocNode) and node.node_type == "SECTION"
):
document_tree_stats.total_sections += 1
if not node.has_any_text_nodes():
document_tree_stats.sections_without_text_nodes += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ TITLE: Requirement title
STATEMENT: Requirement statement. TBC

[/SECTION]

[[SECTION]]
TITLE: New kind of section

[[/SECTION]]
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class Test(E2ECase):
expected_search_results = [
("search-total-sections", 1),
("search-sections-without-any-text", 1),
("search-total-sections", 2),
("search-sections-without-any-text", 2),
("search-total-requirements", 5),
("search-requirements-with-no-uid", 2),
(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[DOCUMENT]
TITLE: Hello world doc

[[SECTION]]
TITLE: Section 1 (with text)

[TEXT]
STATEMENT: >>>
Text
<<<

[[/SECTION]]

[[SECTION]]
TITLE: Section 2 (with text)

[TEXT]
STATEMENT: >>>
Text
<<<

[[/SECTION]]

[[SECTION]]
TITLE: Section 3 (without text)

[[/SECTION]]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ RUN: %check_exists --file "%S/Output/html/project_statistics.html"

RUN: %cat "%S/Output/html/project_statistics.html" | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
CHECK-HTML: Total sections
CHECK-HTML: 3
CHECK-HTML: 6
CHECK-HTML: Sections without any text
CHECK-HTML: 1
CHECK-HTML: 2
CHECK-HTML: Total requirements
CHECK-HTML: 1
Loading