generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 16
Add agent script to update a DocGen instance with json output. #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import argparse | ||
| import json | ||
| import logging | ||
| from pathlib import Path | ||
| from typing import Iterable | ||
|
|
||
| from aws_doc_sdk_examples_tools.doc_gen import DocGen, Example | ||
|
|
||
| # Setup logging | ||
| logging.basicConfig(level=logging.INFO) | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def examples_from_updates(updates_path: Path) -> Iterable[Example]: | ||
| updates = json.loads(updates_path.read_text()) | ||
| examples = [ | ||
| Example( | ||
| id=id, | ||
| file=None, | ||
| languages={}, | ||
| title=update.get("title"), | ||
| title_abbrev=update.get("title_abbrev"), | ||
| synopsis=update.get("synopsis"), | ||
| ) | ||
| for id, update in updates.items() | ||
| ] | ||
| return examples | ||
|
|
||
|
|
||
| def update_examples(doc_gen: DocGen, examples: Iterable[Example]) -> None: | ||
| for example in examples: | ||
| if doc_gen_example := doc_gen.examples.get(example.id): | ||
| doc_gen_example.title = example.title | ||
| doc_gen_example.title_abbrev = example.title_abbrev | ||
| doc_gen_example.synopsis = example.synopsis | ||
| else: | ||
| logger.warning(f"Could not find example with id: {example.id}") | ||
|
|
||
|
|
||
| def main(doc_gen_root: Path, updates_path: Path) -> None: | ||
| doc_gen = DocGen.from_root(doc_gen_root) | ||
| examples = examples_from_updates(updates_path) | ||
| update_examples(doc_gen, examples) | ||
| print( | ||
cpyle0819 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [ | ||
| { | ||
| "title": ex.title, | ||
| "title_abbrev": ex.title_abbrev, | ||
| "synopsis": ex.synopsis, | ||
| } | ||
| for id, ex in doc_gen.examples.items() | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Apply a list of example updates to a doc gen instance" | ||
| ) | ||
| parser.add_argument( | ||
| "--doc-gen-root", required=True, help="Path to a DocGen ready project." | ||
| ) | ||
| parser.add_argument( | ||
| "--updates-path", | ||
| default="example_updates.json", | ||
| help="JSON file containing a list of example updates.", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| doc_gen_root = Path(args.doc_gen_root) | ||
| updates_path = Path(args.updates_path) | ||
| main(doc_gen_root, updates_path) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.