Skip to content

Commit 5148e30

Browse files
authored
Modify yaml writer to normalize metadata when run directly. (#186)
1 parent 9d6b0c4 commit 5148e30

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

aws_doc_sdk_examples_tools/yaml_writer.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
from argparse import ArgumentParser
12
from collections import defaultdict
23
from dataclasses import asdict
34
from pathlib import Path
45
from typing import Any, DefaultDict, Dict, List
6+
7+
import logging
58
import yaml
69

710
from aws_doc_sdk_examples_tools.doc_gen import DocGen
811
from aws_doc_sdk_examples_tools.metadata import Example
912

13+
logging.basicConfig(level=logging.INFO)
14+
15+
logger = logging.getLogger(__file__)
16+
1017

1118
def write_many(root: Path, to_write: Dict[str, str]):
1219
for path, examples in to_write.items():
@@ -104,11 +111,22 @@ def excerpt_dict(excerpt: Dict) -> Dict:
104111
return reordered
105112

106113

107-
# For testing
108-
if __name__ == "__main__":
109-
doc_gen = DocGen.from_root(
110-
Path(__file__).parent / "test_resources" / "doc_gen_test"
114+
def main():
115+
parser = ArgumentParser(
116+
description="Build a DocGen instance and normalize the metadata."
111117
)
118+
parser.add_argument("root", type=str, help="The root of a DocGen project")
119+
120+
args = parser.parse_args()
121+
root = Path(args.root)
122+
123+
if not root.is_dir():
124+
logger.error(f"Expected {root} to be a directory.")
125+
126+
doc_gen = DocGen.from_root(root)
112127
writes = prepare_write(doc_gen.examples)
113-
write_many(Path("/"), writes)
114-
# print(writes)
128+
write_many(root, writes)
129+
130+
131+
if __name__ == "__main__":
132+
main()

0 commit comments

Comments
 (0)