|
10 | 10 | import logging |
11 | 11 | import sys |
12 | 12 |
|
| 13 | +from datetime import datetime, timezone |
13 | 14 | from pathlib import Path |
14 | 15 |
|
15 | 16 | from generate_all_doc_stubs import discover_clients |
|
26 | 27 | NAV_START_MARKER = "# >>> AUTO-NAV >>>" |
27 | 28 | NAV_END_MARKER = "# <<< AUTO-NAV <<<" |
28 | 29 |
|
| 30 | +# Markers in zensical.toml that bound the generated `copyright` line. |
| 31 | +COPYRIGHT_START_MARKER = "# >>> AUTO-COPYRIGHT >>>" |
| 32 | +COPYRIGHT_END_MARKER = "# <<< AUTO-COPYRIGHT <<<" |
| 33 | + |
| 34 | + |
| 35 | +def _replace_block(config: str, start: str, end: str, body: str) -> str: |
| 36 | + """Replace the content between two markers (inclusive of newlines).""" |
| 37 | + if start not in config or end not in config: |
| 38 | + raise ValueError(f"Markers not found. Expected '{start}' and '{end}'.") |
| 39 | + before, _, rest = config.partition(start) |
| 40 | + _, _, after = rest.partition(end) |
| 41 | + return f"{before}{start}\n{body}\n{end}{after}" |
| 42 | + |
29 | 43 |
|
30 | 44 | def _toml_key(value: str) -> str: |
31 | 45 | """Quote a string for use as a TOML key, escaping as a basic string.""" |
@@ -91,18 +105,22 @@ def generate_nav(repo_root: Path) -> bool: |
91 | 105 | logger.error(f"Failed to read {config_path.name}: {e}") |
92 | 106 | return False |
93 | 107 |
|
94 | | - if NAV_START_MARKER not in config or NAV_END_MARKER not in config: |
95 | | - logger.error( |
96 | | - f"AUTO-NAV markers not found in {config_path.name}. " |
97 | | - f"Expected '{NAV_START_MARKER}' and '{NAV_END_MARKER}'." |
| 108 | + year = datetime.now(timezone.utc).year |
| 109 | + copyright_line = ( |
| 110 | + f'copyright = "© {year}, Amazon Web Services, Inc. ' |
| 111 | + f'or its affiliates. All rights reserved."' |
| 112 | + ) |
| 113 | + try: |
| 114 | + updated = _replace_block( |
| 115 | + config, NAV_START_MARKER, NAV_END_MARKER, build_nav_block(clients_dir) |
98 | 116 | ) |
| 117 | + updated = _replace_block( |
| 118 | + updated, COPYRIGHT_START_MARKER, COPYRIGHT_END_MARKER, copyright_line |
| 119 | + ) |
| 120 | + except ValueError as e: |
| 121 | + logger.error(f"Failed to update {config_path.name}: {e}") |
99 | 122 | return False |
100 | | - |
101 | | - nav_block = build_nav_block(clients_dir) |
102 | | - |
103 | | - before, _, rest = config.partition(NAV_START_MARKER) |
104 | | - _, _, after = rest.partition(NAV_END_MARKER) |
105 | | - updated = f"{before}{NAV_START_MARKER}\n{nav_block}\n{NAV_END_MARKER}{after}" |
| 123 | + logger.info(f"Set copyright year to {year}") |
106 | 124 |
|
107 | 125 | try: |
108 | 126 | config_path.write_text(updated) |
|
0 commit comments