Skip to content

Commit ea74e66

Browse files
committed
For tributary validation, load root config, then load and merge tributary config, then load ane merge tributary examples.
1 parent 887fa16 commit ea74e66

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

aws_doc_sdk_examples_tools/doc_gen.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,14 @@ def for_root(
262262
pass
263263

264264
if not incremental:
265-
for path in metadata.glob("*_metadata.yaml"):
266-
self.process_metadata(path)
265+
self.find_and_process_metadata(metadata)
267266

268267
return self
269268

269+
def find_and_process_metadata(self, metadata_path: Path):
270+
for path in metadata_path.glob("*_metadata.yaml"):
271+
self.process_metadata(path)
272+
270273
def process_metadata(self, path: Path) -> "DocGen":
271274
if path in self._loaded:
272275
return self
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
IAMPolicy:
2+
property: json
3+
syntax: json
4+
sdk:
5+
1:
6+
long: "IAM policy"
7+
short: "IAM policy"
8+
guide: "IAM/latest/UserGuide/introduction.html"
9+
api_ref:
10+
uid: "IAMPolicy"
11+
name: "&SAZR;"
12+
link_template: "SomeTemplate"
13+
guide: "&guide-iam-user;"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sts_CustomSdkExample:
2+
title: This example uses an SDK from the tributary config
3+
title_abbrev: This example uses an SDK from the tributary config
4+
synopsis: allow a user to assume any role in your account with the access- name prefix. The role must also be tagged with the same project, team, and cost center tags as the user.
5+
category: IAMPolicyCategory
6+
languages:
7+
IAMPolicy:
8+
versions:
9+
- sdk_version: 1
10+
excerpts:
11+
- description: test
12+
services:
13+
sts: {AssumeRole}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sts_RootSdkExample:
2+
title: This example uses an SDK from the root config
3+
title_abbrev: This example uses an SDK from the root config
4+
synopsis: allow a user to assume any role in your account with the access- name prefix. The role must also be tagged with the same project, team, and cost center tags as the user.
5+
category: IAMPolicyCategory
6+
languages:
7+
Python:
8+
versions:
9+
- sdk_version: 3
10+
excerpts:
11+
- description: test
12+
services:
13+
sts: {AssumeRole}

aws_doc_sdk_examples_tools/validate.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,35 @@ def main():
3838
)
3939
args = parser.parse_args()
4040
root_path = Path(args.root).resolve()
41+
config_path = Path(args.config).resolve() if args.config else None
42+
return validate(root_path, config_path, args.strict_titles, args.doc_gen_only)
4143

42-
if args.config:
43-
config_path = Path(args.config).resolve()
44+
45+
def validate(
46+
root_path: Path, config_path: Path, strict: bool, doc_gen_only: bool
47+
) -> int:
48+
if config_path is not None:
4449
doc_gen = DocGen.default()
45-
doc_gen.merge(
46-
DocGen.from_root(
47-
root=root_path,
48-
validation=ValidationConfig(strict_titles=args.strict_titles),
49-
config=config_path,
50-
)
50+
doc_gen_local = DocGen.from_root(
51+
root=root_path,
52+
validation=ValidationConfig(strict_titles=strict),
53+
config=config_path,
54+
incremental=True,
5155
)
56+
doc_gen.merge(doc_gen_local)
5257
doc_gen.root = root_path
58+
doc_gen.errors = doc_gen_local.errors
59+
metadata = doc_gen.root / ".doc_gen/metadata"
60+
doc_gen.find_and_process_metadata(metadata)
5361
else:
5462
doc_gen = DocGen.from_root(
5563
root=root_path,
56-
validation=ValidationConfig(strict_titles=args.strict_titles),
57-
config=args.config,
64+
validation=ValidationConfig(strict_titles=strict),
5865
)
5966

6067
doc_gen.collect_snippets(snippets_root=root_path)
6168
doc_gen.validate()
62-
if not args.doc_gen_only:
69+
if not doc_gen_only:
6370
check_files(doc_gen.root, doc_gen.validation, doc_gen.errors)
6471
verify_sample_files(doc_gen.root, doc_gen.validation, doc_gen.errors)
6572

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
Test for validate.
6+
"""
7+
8+
from pathlib import Path
9+
10+
from .validate import validate
11+
12+
13+
def test_validate():
14+
root_path = Path(__file__).parent / "test_resources" / "doc_gen_tributary_test"
15+
error_count = validate(root_path, root_path / ".doc_gen/config", False, False)
16+
assert error_count == 0

0 commit comments

Comments
 (0)