Skip to content

Commit 8f2a255

Browse files
committed
When loading a tributary, load new config and merge it with existing config before loading examples so that examples are validated against the combined config.
1 parent cad7e7b commit 8f2a255

File tree

1 file changed

+72
-66
lines changed

1 file changed

+72
-66
lines changed

aws_doc_sdk_examples_tools/doc_gen.py

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -195,74 +195,12 @@ def for_root(
195195

196196
config = config or Path(__file__).parent / "config"
197197

198-
try:
199-
with open(root / ".doc_gen" / "validation.yaml", encoding="utf-8") as file:
200-
validation = yaml.safe_load(file)
201-
validation = validation or {}
202-
self.validation.allow_list.update(validation.get("allow_list", []))
203-
self.validation.sample_files.update(validation.get("sample_files", []))
204-
except Exception:
205-
pass
206-
207-
try:
208-
sdk_path = config / "sdks.yaml"
209-
with sdk_path.open(encoding="utf-8") as file:
210-
meta = yaml.safe_load(file)
211-
sdks, errs = parse_sdks(sdk_path, meta, self.validation.strict_titles)
212-
self.sdks = sdks
213-
self.errors.extend(errs)
214-
except Exception:
215-
pass
216-
217-
try:
218-
services_path = config / "services.yaml"
219-
with services_path.open(encoding="utf-8") as file:
220-
meta = yaml.safe_load(file)
221-
services, service_errors = parse_services(services_path, meta)
222-
self.services = services
223-
for service in self.services.values():
224-
if service.expanded:
225-
self.entities[service.long] = service.expanded.long
226-
self.entities[service.short] = service.expanded.short
227-
self.errors.extend(service_errors)
228-
except Exception:
229-
pass
230-
231-
try:
232-
categories_path = config / "categories.yaml"
233-
with categories_path.open(encoding="utf-8") as file:
234-
meta = yaml.safe_load(file)
235-
standard_categories, categories, errs = parse_categories(
236-
categories_path, meta
237-
)
238-
self.standard_categories = standard_categories
239-
self.categories = categories
240-
self.errors.extend(errs)
241-
except Exception:
242-
pass
243-
244-
try:
245-
entities_config_path = config / "entities.yaml"
246-
with entities_config_path.open(encoding="utf-8") as file:
247-
entities_config = yaml.safe_load(file)
248-
for entity, expanded in entities_config["expanded_override"].items():
249-
self.entities[entity] = expanded
250-
except Exception:
251-
pass
252-
253-
metadata = root / ".doc_gen/metadata"
254-
try:
255-
self.cross_blocks = set(
256-
[
257-
path.name
258-
for path in (metadata.parent / "cross-content").glob("*.xml")
259-
]
260-
)
261-
except Exception:
262-
pass
198+
doc_gen = DocGen.empty()
199+
parse_config(doc_gen, root, config, self.validation.strict_titles)
200+
self.merge(doc_gen)
263201

264202
if not incremental:
265-
self.find_and_process_metadata(metadata)
203+
self.find_and_process_metadata(root / ".doc_gen/metadata")
266204

267205
return self
268206

@@ -401,6 +339,74 @@ def default(self, obj):
401339
return super().default(obj)
402340

403341

342+
def parse_config(doc_gen: DocGen, root: Path, config: Path, strict: bool):
343+
try:
344+
with open(root / ".doc_gen" / "validation.yaml", encoding="utf-8") as file:
345+
validation = yaml.safe_load(file)
346+
validation = validation or {}
347+
doc_gen.validation.allow_list.update(validation.get("allow_list", []))
348+
doc_gen.validation.sample_files.update(validation.get("sample_files", []))
349+
except Exception:
350+
pass
351+
352+
try:
353+
sdk_path = config / "sdks.yaml"
354+
with sdk_path.open(encoding="utf-8") as file:
355+
meta = yaml.safe_load(file)
356+
sdks, errs = parse_sdks(sdk_path, meta, strict)
357+
doc_gen.sdks = sdks
358+
doc_gen.errors.extend(errs)
359+
except Exception:
360+
pass
361+
362+
try:
363+
services_path = config / "services.yaml"
364+
with services_path.open(encoding="utf-8") as file:
365+
meta = yaml.safe_load(file)
366+
services, service_errors = parse_services(services_path, meta)
367+
doc_gen.services = services
368+
for service in doc_gen.services.values():
369+
if service.expanded:
370+
doc_gen.entities[service.long] = service.expanded.long
371+
doc_gen.entities[service.short] = service.expanded.short
372+
doc_gen.errors.extend(service_errors)
373+
except Exception:
374+
pass
375+
376+
try:
377+
categories_path = config / "categories.yaml"
378+
with categories_path.open(encoding="utf-8") as file:
379+
meta = yaml.safe_load(file)
380+
standard_categories, categories, errs = parse_categories(
381+
categories_path, meta
382+
)
383+
doc_gen.standard_categories = standard_categories
384+
doc_gen.categories = categories
385+
doc_gen.errors.extend(errs)
386+
except Exception:
387+
pass
388+
389+
try:
390+
entities_config_path = config / "entities.yaml"
391+
with entities_config_path.open(encoding="utf-8") as file:
392+
entities_config = yaml.safe_load(file)
393+
for entity, expanded in entities_config["expanded_override"].items():
394+
doc_gen.entities[entity] = expanded
395+
except Exception:
396+
pass
397+
398+
metadata = root / ".doc_gen/metadata"
399+
try:
400+
doc_gen.cross_blocks = set(
401+
[
402+
path.name
403+
for path in (metadata.parent / "cross-content").glob("*.xml")
404+
]
405+
)
406+
except Exception:
407+
pass
408+
409+
404410
def parse_examples(
405411
file: Path,
406412
yaml: Dict[str, Any],

0 commit comments

Comments
 (0)