diff --git a/aws_doc_sdk_examples_tools/doc_gen.py b/aws_doc_sdk_examples_tools/doc_gen.py index 69b63d0..0e2a34d 100644 --- a/aws_doc_sdk_examples_tools/doc_gen.py +++ b/aws_doc_sdk_examples_tools/doc_gen.py @@ -262,11 +262,14 @@ def for_root( pass if not incremental: - for path in metadata.glob("*_metadata.yaml"): - self.process_metadata(path) + self.find_and_process_metadata(metadata) return self + def find_and_process_metadata(self, metadata_path: Path): + for path in metadata_path.glob("*_metadata.yaml"): + self.process_metadata(path) + def process_metadata(self, path: Path) -> "DocGen": if path in self._loaded: return self diff --git a/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/config/sdks.yaml b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/config/sdks.yaml new file mode 100644 index 0000000..441eede --- /dev/null +++ b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/config/sdks.yaml @@ -0,0 +1,13 @@ +IAMPolicy: + property: json + syntax: json + sdk: + 1: + long: "IAM policy" + short: "IAM policy" + guide: "IAM/latest/UserGuide/introduction.html" + api_ref: + uid: "IAMPolicy" + name: "&SAZR;" + link_template: "SomeTemplate" + guide: "&guide-iam-user;" diff --git a/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_custom_sdk_metadata.yaml b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_custom_sdk_metadata.yaml new file mode 100644 index 0000000..f6702dd --- /dev/null +++ b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_custom_sdk_metadata.yaml @@ -0,0 +1,13 @@ +sts_CustomSdkExample: + title: This example uses an SDK from the tributary config + title_abbrev: This example uses an SDK from the tributary config + 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. + category: IAMPolicyCategory + languages: + IAMPolicy: + versions: + - sdk_version: 1 + excerpts: + - description: test + services: + sts: {AssumeRole} diff --git a/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_root_sdk_metadata.yaml b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_root_sdk_metadata.yaml new file mode 100644 index 0000000..c748309 --- /dev/null +++ b/aws_doc_sdk_examples_tools/test_resources/doc_gen_tributary_test/.doc_gen/metadata/example_with_root_sdk_metadata.yaml @@ -0,0 +1,13 @@ +sts_RootSdkExample: + title: This example uses an SDK from the root config + title_abbrev: This example uses an SDK from the root config + 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. + category: IAMPolicyCategory + languages: + Python: + versions: + - sdk_version: 3 + excerpts: + - description: test + services: + sts: {AssumeRole} diff --git a/aws_doc_sdk_examples_tools/validate.py b/aws_doc_sdk_examples_tools/validate.py index 325903f..ef980c4 100755 --- a/aws_doc_sdk_examples_tools/validate.py +++ b/aws_doc_sdk_examples_tools/validate.py @@ -38,28 +38,35 @@ def main(): ) args = parser.parse_args() root_path = Path(args.root).resolve() + config_path = Path(args.config).resolve() if args.config else None + return validate(root_path, config_path, args.strict_titles, args.doc_gen_only) - if args.config: - config_path = Path(args.config).resolve() + +def validate( + root_path: Path, config_path: Path, strict: bool, doc_gen_only: bool +) -> int: + if config_path is not None: doc_gen = DocGen.default() - doc_gen.merge( - DocGen.from_root( - root=root_path, - validation=ValidationConfig(strict_titles=args.strict_titles), - config=config_path, - ) + doc_gen_local = DocGen.from_root( + root=root_path, + validation=ValidationConfig(strict_titles=strict), + config=config_path, + incremental=True, ) + doc_gen.merge(doc_gen_local) doc_gen.root = root_path + doc_gen.errors = doc_gen_local.errors + metadata = doc_gen.root / ".doc_gen/metadata" + doc_gen.find_and_process_metadata(metadata) else: doc_gen = DocGen.from_root( root=root_path, - validation=ValidationConfig(strict_titles=args.strict_titles), - config=args.config, + validation=ValidationConfig(strict_titles=strict), ) doc_gen.collect_snippets(snippets_root=root_path) doc_gen.validate() - if not args.doc_gen_only: + if not doc_gen_only: check_files(doc_gen.root, doc_gen.validation, doc_gen.errors) verify_sample_files(doc_gen.root, doc_gen.validation, doc_gen.errors) diff --git a/aws_doc_sdk_examples_tools/validate_test.py b/aws_doc_sdk_examples_tools/validate_test.py index e69de29..8d1c602 100644 --- a/aws_doc_sdk_examples_tools/validate_test.py +++ b/aws_doc_sdk_examples_tools/validate_test.py @@ -0,0 +1,16 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 + +""" +Test for validate. +""" + +from pathlib import Path + +from .validate import validate + + +def test_validate(): + root_path = Path(__file__).parent / "test_resources" / "doc_gen_tributary_test" + error_count = validate(root_path, root_path / ".doc_gen/config", False, False) + assert error_count == 0