|
1 | 1 | from dataclasses import dataclass, field |
2 | 2 | import logging |
3 | 3 | from pathlib import Path |
4 | | -import re |
5 | | -from typing import List, Optional, cast |
6 | 4 |
|
7 | 5 | from aws_doc_sdk_examples_tools.doc_gen import DocGen |
8 | 6 | from aws_doc_sdk_examples_tools.fs import Fs, PathFs |
|
13 | 11 | logger = logging.getLogger(Path(__file__).name) |
14 | 12 |
|
15 | 13 |
|
16 | | -IAM_PATTERN = re.compile(r'"Version"\s*:\s*"20(08|12)-10-17"\s*,') |
17 | | -IAM_PATTERN_SLASHES = re.compile(r'\\"Version\\"\s*:\s*\\"20(08|12)-10-17\\"\s*,') |
18 | | -# This exciting set of unicode characters is the expanded version of the &IAM-2025-waiver; entity. |
19 | | -IAM_WAIVER = '"Version":"2012-10-17",\u0009\u0009\u0020\u0009\u0020\u0009\u0020' |
20 | | -IAM_WAIVER_SLASHES = '\\"Version\\":\\"2012-10-17\\",\u0009\u0009\u0020\u0009\u0020\u0009\u0020' |
21 | | - |
22 | | - |
23 | | -def _iam_replace_all(source: Optional[str]): |
24 | | - if source: |
25 | | - return IAM_PATTERN_SLASHES.subn(IAM_WAIVER_SLASHES, IAM_PATTERN.subn(IAM_WAIVER, source)[0])[0] |
26 | | - return None |
27 | | - |
28 | | - |
29 | | -def _iam_fixup_metadata(meta_folder: Path): |
30 | | - for meta_path in meta_folder.glob("**/*_metadata.yaml"): |
31 | | - with meta_path.open("r") as meta_file: |
32 | | - contents = meta_file.read() |
33 | | - contents = cast(str, _iam_replace_all(contents)) |
34 | | - with meta_path.open("w") as meta_file: |
35 | | - meta_file.write(contents) |
36 | | - |
37 | | - |
38 | | -def _iam_fixup_docgen(doc_gen: DocGen) -> DocGen: |
39 | | - # For performance, do this mutably, but keep the signature open to making DocGen frozen |
40 | | - for snippet in doc_gen.snippets.values(): |
41 | | - snippet.code = cast(str, _iam_replace_all(snippet.code)) |
42 | | - return doc_gen |
43 | | - |
44 | | - |
45 | 14 | @dataclass |
46 | 15 | class Builder: |
47 | 16 | root: Path |
@@ -71,10 +40,8 @@ def write_snippets(self): |
71 | 40 | def run(self): |
72 | 41 | logger.debug("Copying docgen files...") |
73 | 42 | self.copy_doc_gen() |
74 | | - _iam_fixup_metadata(self.dest) |
75 | 43 | logger.debug("Collecting snippets...") |
76 | 44 | self._doc_gen.collect_snippets() |
77 | | - self._doc_gen = _iam_fixup_docgen(self._doc_gen) |
78 | 45 | logger.debug("Writing snippets...") |
79 | 46 | self.write_snippets() |
80 | 47 |
|
|
0 commit comments