Skip to content

Commit

Permalink
Move some passthrough cmd to export --formats sdoc
Browse files Browse the repository at this point in the history
We have two commands for similar tasks:

- 'strictdoc export' does sdoc to <other> conversion and filtering.
- 'strictdoc passthrough' does sdoc to sdoc conversion and filtering.

Both commands can be unified by introducing a new export output format
"sdoc". For example:

 strictdoc passthrough --view PRINT_VIEW            # old
 strictdoc export --view PRINT_VIEW --formats sdoc  # new

 strictdoc passtrough --filter-requirements FILTER_REQUIREMENTS             # old
 strictdoc export --filter-requirements FILTER_REQUIREMENTS --formats sdoc  # new

 strictdoc passthrough --filter-sections FILTER_SECTIONS            # old
 strictdoc export --filter-sections FILTER_SECTIONS --formats sdoc  # new

This change removes keeps the passthrough CLI parser for compatibility
but changes it so that the result is internally handled by export
action.

Relates to #1913.
  • Loading branch information
haxtibal committed Aug 21, 2024
1 parent 45bb880 commit ea0b204
Show file tree
Hide file tree
Showing 39 changed files with 352 additions and 209 deletions.
8 changes: 4 additions & 4 deletions docs/strictdoc_01_user_guide.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ StrictDoc supports the automatic generation of machine identifiers (MIDs). This
OPTIONS:
ENABLE_MID: True

When the ``ENABLE_MID`` option is enabled, StrictDoc automatically generates MID fields whenever the document is written back to the file system. On the web server, MIDs are generated automatically when a document, section, or requirement is saved. In the command-line interface, the generation of ``MID`` can be initiated with a ``passthrough`` command. Executing ``strictdoc passthrough`` on a document with ``ENABLE_MID: True`` results in all nodes having auto-generated MIDs. Implementing the ENABLE_MID option on a per-document basis allows for the integration of MID-enabled documents alongside third-party documents where the MID feature may not be necessary or desired.
When the ``ENABLE_MID`` option is enabled, StrictDoc automatically generates MID fields whenever the document is written back to the file system. On the web server, MIDs are generated automatically when a document, section, or requirement is saved. In the command-line interface, the generation of ``MID`` can be initiated with a ``export`` command. Executing ``strictdoc export --formats sdoc`` on a document with ``ENABLE_MID: True`` results in all nodes having auto-generated MIDs. Implementing the ENABLE_MID option on a per-document basis allows for the integration of MID-enabled documents alongside third-party documents where the MID feature may not be necessary or desired.

Machine identifiers (MIDs) differ from and do not replace unique identifiers (UIDs). A requirement, section, or document node may have both ``MID`` and ``UID`` fields defined. For example:

Expand Down Expand Up @@ -1691,7 +1691,7 @@ TITLE: Search and filtering
[FREETEXT]
StrictDoc supports the search and filtering of document content.

The web interface includes the Search screen, designed for conducting queries against a document tree. The command-line interface supports filtering of requirements and sections through the ``export`` and ``passthrough`` commands.
The web interface includes the Search screen, designed for conducting queries against a document tree. The command-line interface supports filtering of requirements and sections through the ``export`` commands.
[/FREETEXT]

[SECTION]
Expand Down Expand Up @@ -1738,7 +1738,7 @@ Important rules:
TITLE: Filtering content

[FREETEXT]
Both ``export`` and ``passthrough`` command-line interface commands support filtering documentation content with ``--filter-requirements`` and ``--filter-sections`` options.
Both ``export`` command-line interface commands support filtering documentation content with ``--filter-requirements`` and ``--filter-sections`` options.

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.

Expand Down Expand Up @@ -2893,7 +2893,7 @@ The ``TEXT`` node is now included to a default StrictDoc grammar by default. If
... REQUIREMENT fields
... Optionally other elements definitions.

The ``strictdoc passthrough --free-text-to-text ...`` command can be used for converting all FREETEXT nodes to TEXT nodes automatically. See ``strictdoc passthrough --help`` for more details.
The ``strictdoc export --formats sdoc --free-text-to-text ...`` command can be used for converting all FREETEXT nodes to TEXT nodes automatically. See ``strictdoc export --help`` for more details.
<<<

[/SECTION]
Expand Down
5 changes: 1 addition & 4 deletions docs/strictdoc_21_L2_StrictDoc_Requirements.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ A consistent import/export roundtrip implementation and testing reduces the risk
RELATIONS:
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/core/actions/passthrough_action.py
- TYPE: File
FORMAT: Sourcecode
VALUE: strictdoc/core/actions/passthrough_action.py
VALUE: strictdoc/core/actions/export_action.py
- TYPE: File
FORMAT: Sourcecode
VALUE: tests/unit/strictdoc/backend/sdoc/test_dsl_passthrough.py
Expand Down
31 changes: 3 additions & 28 deletions strictdoc/cli/cli_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,6 @@ def __init__(self, input_path, output_path, parser):
self.parser = parser


class PassthroughCommandConfig:
def __init__(
self,
input_file,
output_dir: Optional[str],
filter_requirements: Optional[str],
filter_sections: Optional[str],
free_text_to_text: bool,
view: Optional[str],
):
self.input_file = input_file
self.output_dir: Optional[str] = output_dir
self.filter_requirements: Optional[str] = filter_requirements
self.filter_sections: Optional[str] = filter_sections
self.free_text_to_text: bool = free_text_to_text
self.view: Optional[str] = view


@auto_described
class ServerCommandConfig:
def __init__(
Expand Down Expand Up @@ -147,6 +129,7 @@ def __init__(
reqif_enable_mid: bool,
view: Optional[str],
chromedriver: Optional[str],
free_text_to_text: bool,
):
assert isinstance(input_paths, list), f"{input_paths}"
self.input_paths: List[str] = input_paths
Expand All @@ -167,6 +150,7 @@ def __init__(
self.view: Optional[str] = view
self.output_html_root: str = os.path.join(output_dir, "html")
self.chromedriver: Optional[str] = chromedriver
self.free_text_to_text: bool = free_text_to_text

def get_path_to_config(self) -> str:
# FIXME: The control flow can be improved.
Expand Down Expand Up @@ -265,16 +249,6 @@ def is_manage_autouid_command(self):
self.args.command == "manage" and self.args.subcommand == "auto-uid"
)

def get_passthrough_config(self) -> PassthroughCommandConfig:
return PassthroughCommandConfig(
self.args.input_file,
self.args.output_dir,
filter_requirements=self.args.filter_requirements,
filter_sections=self.args.filter_sections,
free_text_to_text=self.args.free_text_to_text,
view=self.args.view,
)

def get_export_config(self) -> ExportCommandConfig:
project_title: Optional[str] = self.args.project_title

Expand All @@ -299,6 +273,7 @@ def get_export_config(self) -> ExportCommandConfig:
self.args.reqif_profile,
self.args.reqif_multiline_is_xhtml,
self.args.reqif_enable_mid,
self.args.free_text_to_text,
self.args.view,
self.args.chromedriver,
)
Expand Down
76 changes: 74 additions & 2 deletions strictdoc/cli/command_parser_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"excel",
"reqif-sdoc",
"reqifz-sdoc",
"sdoc",
"spdx",
]
EXCEL_PARSERS = ["basic"]
Expand Down Expand Up @@ -250,6 +251,14 @@ def add_export_command(parent_command_parser):
"If not given, chromedriver is downloaded and saved to "
"strictdoc cache.",
)
command_parser_export.add_argument(
"--free-text-to-text",
action="store_true",
help=(
"This option makes all FREETEXT nodes to be converted to the new "
"TEXT nodes."
),
)
add_config_argument(command_parser_export)

@staticmethod
Expand Down Expand Up @@ -380,13 +389,19 @@ def add_version_command(parent_command_parser):

@staticmethod
def add_passthrough_command(parent_command_parser):
# passthrough command is kept for backwards compatibility. It will
# internally be handled as export --formats sdoc.
command_parser_passthrough = parent_command_parser.add_parser(
"passthrough",
help="Read an SDoc file, then output it again. (used for testing)",
help="Read an SDoc file, then output it again. Deprecated, use "
"strictdoc export --formats sdoc instead.",
formatter_class=formatter,
)
command_parser_passthrough.add_argument(
"input_file", type=str, help="Path to the input SDoc file."
"input_paths",
type=str,
nargs="+",
help="One or more folders with *.sdoc files",
)
command_parser_passthrough.add_argument(
"--output-dir",
Expand Down Expand Up @@ -417,6 +432,63 @@ def add_passthrough_command(parent_command_parser):
help="Choose which view will be exported.",
)

# Hidden default values to make deprecated passthrough parser compatible
# with SDocArgsParser.get_export_config.
command_parser_passthrough.add_argument(
"--project-title", const=None, help=argparse.SUPPRESS
)
command_parser_passthrough.add_argument(
"--formats",
default=["sdoc"],
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--fields",
default=None,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--generate-bundle-document",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--no-parallelization",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--enable-mathjax",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--included-documents",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--reqif-profile",
default=None,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--reqif-multiline-is-xhtml",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--reqif-enable-mid",
default=False,
help=argparse.SUPPRESS,
)
command_parser_passthrough.add_argument(
"--chromedriver",
default=None,
help=argparse.SUPPRESS,
)
add_config_argument(command_parser_passthrough)

@staticmethod
def add_dump_command(parent_command_parser):
command_parser_dump_grammar = parent_command_parser.add_parser(
Expand Down
30 changes: 7 additions & 23 deletions strictdoc/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
ImportExcelCommandConfig,
ImportReqIFCommandConfig,
ManageAutoUIDCommandConfig,
PassthroughCommandConfig,
create_sdoc_args_parser,
)
from strictdoc.commands.about_command import AboutCommand
Expand All @@ -33,7 +32,6 @@
from strictdoc.commands.version_command import VersionCommand
from strictdoc.core.actions.export_action import ExportAction
from strictdoc.core.actions.import_action import ImportAction
from strictdoc.core.actions.passthrough_action import PassthroughAction
from strictdoc.core.project_config import ProjectConfig, ProjectConfigLoader
from strictdoc.helpers.exception import StrictDocException
from strictdoc.helpers.parallelizer import Parallelizer
Expand All @@ -44,27 +42,13 @@ def _main(parallelizer: Parallelizer) -> None:
parser = create_sdoc_args_parser()

project_config: ProjectConfig
if parser.is_passthrough_command:
passthrough_config: PassthroughCommandConfig = (
parser.get_passthrough_config()
)
input_file = passthrough_config.input_file
if not os.path.exists(input_file):
sys.stdout.flush()
message = "error: passthrough command's input path is neither a folder or a file."
print(f"{message}: {input_file}") # noqa: T201
sys.exit(1)

project_config = ProjectConfigLoader.load_from_path_or_get_default(
path_to_config=os.getcwd(),
environment=environment,
)
project_config.integrate_passthrough_config(passthrough_config)

passthrough_action = PassthroughAction()
passthrough_action.passthrough(project_config)

elif parser.is_export_command:
if parser.is_passthrough_command or parser.is_export_command:
if parser.is_passthrough_command:
print( # noqa: T201
"warning: passthrough is deprecated, use strictdoc "
"export --formats sdoc instead."
)
export_config: ExportCommandConfig = parser.get_export_config()
try:
export_config.validate()
Expand Down Expand Up @@ -141,7 +125,7 @@ def _main(parallelizer: Parallelizer) -> None:
environment=environment,
)
# FIXME: This must be improved.
project_config.export_input_paths = [manage_config.input_path]
project_config.input_paths = [manage_config.input_path]
# FIXME: This must be improved.
project_config.autouuid_include_sections = (
manage_config.include_sections
Expand Down
4 changes: 2 additions & 2 deletions strictdoc/commands/diff_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def execute(
project_config_copy_lhs: ProjectConfig = deepcopy(project_config)
project_config_copy_rhs: ProjectConfig = deepcopy(project_config)

project_config_copy_lhs.export_input_paths = [lhs_export_input_abs_path]
project_config_copy_rhs.export_input_paths = [rhs_export_input_abs_path]
project_config_copy_lhs.input_paths = [lhs_export_input_abs_path]
project_config_copy_rhs.input_paths = [rhs_export_input_abs_path]

change_container: ChangeContainer = ChangeGenerator.generate(
lhs_project_config=project_config_copy_lhs,
Expand Down
Loading

0 comments on commit ea0b204

Please sign in to comment.