Skip to content

Commit 62089ef

Browse files
authored
Add --include flag to yaml writer to limit _metadata files loaded (#200)
1 parent 5f9b868 commit 62089ef

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

aws_doc_sdk_examples_tools/yaml_writer.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections import defaultdict
33
from dataclasses import asdict
44
from pathlib import Path
5-
from typing import Any, DefaultDict, Dict, List, Tuple
5+
from typing import Any, DefaultDict, Dict, List, Optional, Tuple
66

77
import logging
88
import yaml
@@ -112,7 +112,7 @@ def excerpt_dict(excerpt: Dict) -> Dict:
112112
return reordered
113113

114114

115-
def collect_yaml(root: Path) -> Dict[str, Dict]:
115+
def collect_yaml(root: Path, include: Optional[List[str]] = None) -> Dict[str, Dict]:
116116
yaml_files: Dict[str, Dict] = {}
117117
metadata_dir = root / ".doc_gen" / "metadata"
118118

@@ -122,6 +122,12 @@ def collect_yaml(root: Path) -> Dict[str, Dict]:
122122
for yaml_path in metadata_dir.glob("**/*.yaml"):
123123
rel_path = yaml_path.relative_to(root)
124124

125+
if (
126+
include is not None
127+
and yaml_path.name.replace("_metadata.yaml", "") not in include
128+
):
129+
continue
130+
125131
with open(yaml_path, "r") as file:
126132
try:
127133
content = yaml.safe_load(file)
@@ -157,18 +163,21 @@ def main():
157163
description="Build a DocGen instance and normalize the metadata."
158164
)
159165
parser.add_argument("root", type=str, help="The root of a DocGen project")
166+
parser.add_argument(
167+
"--include", nargs="*", default=None, help="Packages to include"
168+
)
160169

161170
args = parser.parse_args()
162171
root = Path(args.root)
163172

164173
if not root.is_dir():
165174
logger.error(f"Expected {root} to be a directory.")
166175

167-
before_values = collect_yaml(root)
176+
before_values = collect_yaml(root, args.include)
168177
doc_gen = DocGen.from_root(root)
169178
writes = prepare_write(doc_gen.examples)
170179
write_many(root, writes)
171-
after_values = collect_yaml(root)
180+
after_values = collect_yaml(root, args.include)
172181

173182
if before_values != after_values:
174183
differences = report_yaml_differences(before_values, after_values)

0 commit comments

Comments
 (0)