From 6213a41e9fd8e9b7cae8409d627b2335fdaf8345 Mon Sep 17 00:00:00 2001 From: David Souther Date: Wed, 15 Jan 2025 12:58:07 -0500 Subject: [PATCH] doc_gen_cli collects and stores snippets in a second file (#131) * doc_gen_cli collects and stores snippets in a second file * Update tests --- aws_doc_sdk_examples_tools/doc_gen_cli.py | 21 ++++++++++++++++++- .../doc_gen_cli_test.py | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/aws_doc_sdk_examples_tools/doc_gen_cli.py b/aws_doc_sdk_examples_tools/doc_gen_cli.py index 79c5069..e388a40 100644 --- a/aws_doc_sdk_examples_tools/doc_gen_cli.py +++ b/aws_doc_sdk_examples_tools/doc_gen_cli.py @@ -7,7 +7,6 @@ import logging from .doc_gen import DocGen, DocGenEncoder -from .entities import EntityErrors logging.basicConfig(level=logging.INFO) @@ -28,6 +27,12 @@ def main(): type=str, help="Output a JSON version of the computed DocGen with some properties stripped out. Includes any errors.", ) + parser.add_argument( + "--write-snippets", + default="doc_gen_snippets.json", + type=str, + help="Output a JSON version of the computed DocGen with only snippets and snippet files. Separates snippet content from metadata content.", + ) parser.add_argument( "--strict", @@ -61,6 +66,20 @@ def main(): with open(args.write_json, "w") as out: out.write(serialized) + if args.write_snippets: + for root in args.from_root: + merged_doc_gen.collect_snippets(Path(root)) + + serialized_snippets = json.dumps( + { + "snippets": merged_doc_gen.snippets, + "snippet_files": merged_doc_gen.snippet_files, + }, + cls=DocGenEncoder, + ) + with open(args.write_snippets, "w") as out: + out.write(serialized_snippets) + if __name__ == "__main__": main() diff --git a/aws_doc_sdk_examples_tools/doc_gen_cli_test.py b/aws_doc_sdk_examples_tools/doc_gen_cli_test.py index 85cb72b..ddd66fb 100644 --- a/aws_doc_sdk_examples_tools/doc_gen_cli_test.py +++ b/aws_doc_sdk_examples_tools/doc_gen_cli_test.py @@ -76,6 +76,7 @@ def test_doc_gen_strict_option(strict, should_raise, patched_environment): mock_args = Namespace( from_root=["/mock/path"], write_json="mock_output.json", + write_snippets="", strict=strict, skip_entity_expansion=False, ) @@ -94,6 +95,7 @@ def test_skip_entity_expansion(patched_environment): mock_args = Namespace( from_root=["/mock/path"], write_json="mock_output.json", + write_snippets="", strict=False, skip_entity_expansion=True, ) @@ -111,6 +113,7 @@ def test_default_entity_expansion(patched_environment): mock_args = Namespace( from_root=["/mock/path"], write_json="mock_output.json", + write_snippets="", strict=False, skip_entity_expansion=False, )