Skip to content

Commit 8ce981e

Browse files
authored
Merge pull request #2519 from strictdoc-project/stanislaw/section_filter
feat(export/html): remove legacy --filter-sections, rename: --filter-requirements -> --filter-nodes
2 parents 12faf0d + 13fdce7 commit 8ce981e

File tree

24 files changed

+81
-97
lines changed

24 files changed

+81
-97
lines changed

docs/strictdoc_01_user_guide.sdoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,15 +3809,15 @@ TITLE: Filtering content
38093809
[TEXT]
38103810
MID: d52d86750ad54ce1b3263ebb092451c0
38113811
STATEMENT: >>>
3812-
Both ``export`` command-line interface commands support filtering documentation content with ``--filter-requirements`` and ``--filter-sections`` options.
3812+
The ``export`` command-line interface command supports filtering documentation content with the ``--filter-nodes`` option.
38133813

3814-
Both options are based on the Query Engine, so the same rules that are valid for Search also apply for filtering. When a filter is applied, only the whitelisted requirements/sections will be exported.
3814+
The option is based on the Query Engine, so the same rules that are valid for Search also apply for filtering. When a filter is applied, only the whitelisted nodes will be exported.
38153815

38163816
Example:
38173817

38183818
.. code-block::
38193819

3820-
strictdoc export . --filter-requirements '"System" in node["TITLE"]'
3820+
strictdoc export . --filter-nodes '"System" in node["TITLE"]'
38213821
<<<
38223822

38233823
[[/SECTION]]

strictdoc/cli/cli_arg_parser.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def __init__(
137137
no_parallelization: bool,
138138
enable_mathjax: bool,
139139
included_documents: bool,
140-
filter_requirements: Optional[str],
141-
filter_sections: Optional[str],
140+
filter_nodes: Optional[str],
142141
reqif_profile: Optional[str],
143142
reqif_multiline_is_xhtml: bool,
144143
reqif_enable_mid: bool,
@@ -156,8 +155,7 @@ def __init__(
156155
self.no_parallelization: bool = no_parallelization
157156
self.enable_mathjax: bool = enable_mathjax
158157
self.included_documents: bool = included_documents
159-
self.filter_requirements: Optional[str] = filter_requirements
160-
self.filter_sections: Optional[str] = filter_sections
158+
self.filter_nodes: Optional[str] = filter_nodes
161159
self.reqif_profile: Optional[str] = reqif_profile
162160
self.reqif_multiline_is_xhtml: bool = reqif_multiline_is_xhtml
163161
self.reqif_enable_mid: bool = reqif_enable_mid
@@ -281,8 +279,7 @@ def get_export_config(self) -> ExportCommandConfig:
281279
self.args.no_parallelization,
282280
self.args.enable_mathjax,
283281
self.args.included_documents,
284-
self.args.filter_requirements,
285-
self.args.filter_sections,
282+
self.args.filter_nodes,
286283
self.args.reqif_profile,
287284
self.args.reqif_multiline_is_xhtml,
288285
self.args.reqif_enable_mid,

strictdoc/cli/command_parser_builder.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,14 @@ def add_export_command(
238238
"SPEC-OBJECT's IDENTIFIER and vice versa when exporting/importing."
239239
),
240240
)
241+
# FIXME: --filter-requirements will be removed in 2026.
241242
command_parser_export.add_argument(
243+
"--filter-nodes",
242244
"--filter-requirements",
245+
dest="filter_nodes",
243246
type=str,
244247
help="Filter which requirements will be exported.",
245248
)
246-
command_parser_export.add_argument(
247-
"--filter-sections",
248-
type=str,
249-
help="Filter which sections will be exported.",
250-
)
251249
command_parser_export.add_argument(
252250
"--view",
253251
type=str,
@@ -429,16 +427,14 @@ def add_passthrough_command(
429427
type=str,
430428
help="A directory where to output the SDoc files to.",
431429
)
430+
# FIXME: --filter-requirements will be removed in 2026.
432431
command_parser_passthrough.add_argument(
432+
"--filter-nodes",
433433
"--filter-requirements",
434+
dest="filter_nodes",
434435
type=str,
435436
help="Filter which requirements will be exported.",
436437
)
437-
command_parser_passthrough.add_argument(
438-
"--filter-sections",
439-
type=str,
440-
help="Filter which sections will be exported.",
441-
)
442438
command_parser_passthrough.add_argument(
443439
"--view",
444440
type=str,

strictdoc/core/project_config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ def __init__(
206206
self.export_formats: Optional[List[str]] = None
207207
self.export_included_documents: bool = False
208208
self.generate_bundle_document: bool = False
209-
self.filter_requirements: Optional[str] = None
210-
self.filter_sections: Optional[str] = None
209+
self.filter_nodes: Optional[str] = None
211210

212211
self.excel_export_fields: Optional[List[str]] = None
213212

@@ -327,8 +326,7 @@ def integrate_export_config(
327326
self.export_formats = export_config.formats
328327
self.export_included_documents = export_config.included_documents
329328
self.generate_bundle_document = export_config.generate_bundle_document
330-
self.filter_requirements = export_config.filter_requirements
331-
self.filter_sections = export_config.filter_sections
329+
self.filter_nodes = export_config.filter_nodes
332330
self.excel_export_fields = export_config.fields
333331
self.view = export_config.view
334332
self.chromedriver = export_config.chromedriver

strictdoc/core/traceability_index_builder.py

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -802,71 +802,64 @@ def child_cycle_traverse_(node_id: str) -> Any:
802802
def _filter_nodes(
803803
project_config: ProjectConfig, traceability_index: TraceabilityIndex
804804
) -> None:
805-
if (
806-
project_config.filter_requirements is not None
807-
or project_config.filter_sections is not None
808-
):
809-
query_reader = QueryReader()
810-
requirements_query_object: Union[QueryObject, QueryNullObject]
811-
try:
812-
if project_config.filter_requirements is not None:
813-
requirements_query = query_reader.read(
814-
project_config.filter_requirements
815-
)
816-
requirements_query_object = QueryObject(
817-
requirements_query, traceability_index
818-
)
819-
else:
820-
requirements_query_object = QueryNullObject()
821-
except TextXSyntaxError:
822-
# FIXME: This must throw a StrictDocException.
823-
print("error: Cannot parse filter query.") # noqa: T201
824-
sys.exit(1)
825-
try:
826-
for document in traceability_index.document_tree.document_list:
827-
document_iterator = (
828-
traceability_index.get_document_iterator(document)
829-
)
830-
for node, _ in document_iterator.all_content():
805+
if project_config.filter_nodes is None:
806+
return
807+
808+
query_reader = QueryReader()
809+
requirements_query_object: Union[QueryObject, QueryNullObject]
810+
try:
811+
requirements_query = query_reader.read(project_config.filter_nodes)
812+
requirements_query_object = QueryObject(
813+
requirements_query, traceability_index
814+
)
815+
except TextXSyntaxError as textx_syntax_error_:
816+
raise StrictDocException(
817+
"Cannot parse filter query."
818+
) from textx_syntax_error_
819+
820+
try:
821+
for document in traceability_index.document_tree.document_list:
822+
document_iterator = traceability_index.get_document_iterator(
823+
document
824+
)
825+
for node, _ in document_iterator.all_content():
826+
if (
827+
isinstance(node, SDocNode)
828+
and node.node_type == "SECTION"
829+
and not requirements_query_object.evaluate(node)
830+
):
831+
node.ng_whitelisted = False
832+
# If the node is the last one, we check if all other
833+
# nodes are filtered out and if so, mark the parent
834+
# section node as not whitelisted as well.
831835
if (
832-
isinstance(node, SDocNode)
833-
and node.node_type == "SECTION"
834-
and not requirements_query_object.evaluate(node)
836+
node.parent.section_contents[
837+
len(node.parent.section_contents) - 1
838+
]
839+
== node
835840
):
836-
node.ng_whitelisted = False
837-
# If the node is the last one, we check if all other
838-
# nodes are filtered out and if so, mark the parent
839-
# section node as not whitelisted as well.
840841
if (
841-
node.parent.section_contents[
842-
len(node.parent.section_contents) - 1
843-
]
844-
== node
845-
):
846-
if (
847-
isinstance(node.parent, SDocNode)
848-
and node.parent.node_type == "SECTION"
849-
):
850-
node.parent.blacklist_if_needed()
851-
852-
elif isinstance(
853-
node, SDocNode
854-
) and not requirements_query_object.evaluate(node):
855-
node.ng_whitelisted = False
856-
# If the node is the last one, we check if all other
857-
# nodes are filtered out and if so, mark the parent
858-
# section node as not whitelisted as well.
859-
if (
860-
node.parent.section_contents[
861-
len(node.parent.section_contents) - 1
862-
]
863-
== node
842+
isinstance(node.parent, SDocNode)
843+
and node.parent.node_type == "SECTION"
864844
):
865845
node.parent.blacklist_if_needed()
866846

867-
except (AttributeError, NameError, TypeError) as attribute_error_:
868-
print( # noqa: T201
869-
"error: cannot apply a filter query to a node: "
870-
f"{attribute_error_}"
871-
)
872-
sys.exit(1)
847+
elif isinstance(
848+
node, SDocNode
849+
) and not requirements_query_object.evaluate(node):
850+
node.ng_whitelisted = False
851+
# If the node is the last one, we check if all other
852+
# nodes are filtered out and if so, mark the parent
853+
# section node as not whitelisted as well.
854+
if (
855+
node.parent.section_contents[
856+
len(node.parent.section_contents) - 1
857+
]
858+
== node
859+
):
860+
node.parent.blacklist_if_needed()
861+
862+
except (AttributeError, NameError, TypeError) as attribute_error_:
863+
raise StrictDocException(
864+
f"Cannot apply a filter query to a node: {attribute_error_}"
865+
) from attribute_error_

tests/integration/features/html/--filter-requirements/01_basic_filter/test.itest renamed to tests/integration/features/html/--filter-nodes/01_basic_filter/test.itest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
RUN: %strictdoc export %S --output-dir %T --filter-requirements='("2" in node["TITLE"] or "4" in node["TITLE"])' | filecheck %s --dump-input=fail
2+
RUN: rm -rf %T/*
3+
RUN: %strictdoc export %S --output-dir %T --filter-nodes='("2" in node["TITLE"] or "4" in node["TITLE"])' | filecheck %s --dump-input=fail
24
CHECK: Published: Hello world doc
35

46
RUN: %cat %T/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RUN: %strictdoc export %S --output-dir %T --filter-requirements='("1" in node["TITLE"] or "2" in node["TITLE"])' | filecheck %s --dump-input=fail
1+
RUN: %strictdoc export %S --output-dir %T --filter-nodes='("1" in node["TITLE"] or "2" in node["TITLE"])' | filecheck %s --dump-input=fail
22
CHECK: Published: Hello world doc
33

44
RUN: %cat %T/html/index.html | filecheck %s --dump-input=fail --check-prefix CHECK-HTML

0 commit comments

Comments
 (0)