Skip to content

Commit

Permalink
Fix writeme to handle new READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
meyertst-aws committed Jun 12, 2024
1 parent abe92e1 commit 65cc0b5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions .tools/readmes/render.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

from collections import defaultdict
import datetime
import logging
import os
import re
from jinja2 import Environment, FileSystemLoader, select_autoescape
from collections import defaultdict
from operator import itemgetter
from pathlib import Path

from jinja2 import Environment, FileSystemLoader, select_autoescape

import config

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -47,8 +48,8 @@ def __init__(self, scanner, sdk_ver, safe, svc_folder=None):
self.lang_config["service_folder"] = svc_folder
else:
if (
"service_folder_overrides" in self.lang_config
and scanner.svc_name in self.lang_config["service_folder_overrides"]
"service_folder_overrides" in self.lang_config
and scanner.svc_name in self.lang_config["service_folder_overrides"]
):
overrides = self.lang_config["service_folder_overrides"]
self.lang_config["service_folder"] = overrides[scanner.svc_name]
Expand Down Expand Up @@ -90,9 +91,9 @@ def _transform_sdk(self):
def _transform_service(self):
pre_svc = self.scanner.service()
if (
"expanded" not in pre_svc
or "blurb" not in pre_svc
or "guide" not in pre_svc
"expanded" not in pre_svc
or "blurb" not in pre_svc
or "guide" not in pre_svc
):
logger.error(
"%s entry in services.yaml does not have required entity expansions, blurb, or guide "
Expand Down Expand Up @@ -129,14 +130,14 @@ def _transform_hello(self, pre_hello):
post_hello.append(action)
return sorted(post_hello, key=itemgetter("title_abbrev"))


def _transform_actions(self, pre_actions):
post_actions = []
for pre_id, pre in pre_actions.items():
try:
api = next(iter(pre["services"][self.scanner.svc_name]))
except:
raise MissingMetadataError(f"Action not found for example {pre_id} and service {self.scanner.svc_name}.")
raise MissingMetadataError(
f"Action not found for example {pre_id} and service {self.scanner.svc_name}.")
action = {
"title_abbrev": api,
"file": self.scanner.snippet(
Expand Down Expand Up @@ -218,7 +219,7 @@ def _transform_crosses(self):
base_folder = f"{config.language[self.scanner.lang_name][self.sdk_ver]['base_folder']}/"
if base_folder in github:
github = (
self._lang_level_double_dots() + github.split(base_folder, 1)[1]
self._lang_level_double_dots() + github.split(base_folder, 1)[1]
)
cross = {
"title_abbrev": pre["title_abbrev"],
Expand Down Expand Up @@ -247,7 +248,7 @@ def _scrape_customs(self, readme_filename, sdk_short):
with open(readme_filename, "r", encoding="utf-8") as readme:
for line in readme.readlines():
if line.lstrip().startswith("<!--custom") and line.rstrip().endswith(
"start-->"
"start-->"
):
tag_parts = line.split(".")
section = tag_parts[1]
Expand All @@ -260,7 +261,7 @@ def _scrape_customs(self, readme_filename, sdk_short):
else:
customs[section] = ""
elif line.lstrip().startswith("<!--custom") and line.rstrip().endswith(
"end-->"
"end-->"
):
end_section = line.split(".")[1]
if end_section != section:
Expand Down Expand Up @@ -331,11 +332,13 @@ def write(self):
self.readme_filename,
f'{self.lang_config["service_folder"]}/{config.saved_readme}',
)
os.remove(self.readme_filename) # Do this so that new files are always updated to the correct case (README.md).
if Path(self.readme_filename).exists():
os.remove(self.readme_filename) # Do this so that new files are always updated to the correct case (README.md).
with open(self.readme_filename, "w", encoding="utf-8") as f:
f.write(self.readme_text)
print(f"Updated {self.readme_filename}.")


def check(self):
with open(self.readme_filename, "r", encoding="utf-8") as f:
readme_current = f.read()
Expand Down

0 comments on commit 65cc0b5

Please sign in to comment.