Skip to content

Commit

Permalink
tools: Expand entities with tools entities expander.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther committed Sep 26, 2024
1 parent 4ed9b71 commit f2e46f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
16 changes: 5 additions & 11 deletions .tools/readmes/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Dict, List, Tuple

import config
from aws_doc_sdk_examples_tools.entities import expand_all_entities
from aws_doc_sdk_examples_tools.metadata import Example
from aws_doc_sdk_examples_tools.sdks import Sdk
from aws_doc_sdk_examples_tools.services import Service
Expand Down Expand Up @@ -202,16 +203,6 @@ def _transform_custom_categories(self) -> Dict[str, List[Dict[str, str]]]:
sorted_cats[key] = post_cats[key]
return sorted_cats

def _expand_entities(self, readme_text: str) -> str:
entities = set(re.findall(r"&[\dA-Za-z-_]+;", readme_text))
for entity in entities:
expanded = self.scanner.expand_entity(entity)
if expanded is not None:
readme_text = readme_text.replace(entity, expanded)
else:
logger.warning("Entity found with no expansion defined: %s", entity)
return readme_text

def _lang_level_double_dots(self) -> str:
return "../" * self.lang_config["service_folder"].count("/")

Expand Down Expand Up @@ -313,7 +304,10 @@ def render(self) -> RenderStatus:
customs=customs,
unsupported=unsupported,
)
self.readme_text = self._expand_entities(self.readme_text)
[text, errors] = expand_all_entities(self.readme_text, self.scanner.doc_gen.entities)
if errors:
raise errors
self.readme_text = text

# Check if the rendered text is different from the existing file
if self.read_current() == self.readme_text:
Expand Down
14 changes: 0 additions & 14 deletions .tools/readmes/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def __init__(self, doc_gen: DocGen):
self.sdk_ver: int = -1
self.svc_name: str = ""
self.snippets = None
self.entities: Dict[str, str] = {}
self._prepare_entities()
self.examples: Dict[str, List[Example]] = {}
self._build_examples()
self.hellos: Dict[str, Example] = {}
Expand All @@ -41,15 +39,6 @@ def __init__(self, doc_gen: DocGen):
self.crosses: Dict[str, Example] = {}
self.cross_scenarios: Dict[str, Example] = {}

def _prepare_entities(self):
for svc in self.services().values():
if svc.expanded:
self.entities[svc.long] = svc.expanded.long
self.entities[svc.short] = svc.expanded.short
# config entities override
for entity, expanded in config.entities.items():
self.entities[entity] = expanded

def load_crosses(self):
self.doc_gen.process_metadata(
self.doc_gen.root / ".doc_gen" / "metadata" / "cross_metadata.yaml"
Expand Down Expand Up @@ -112,9 +101,6 @@ def service(self) -> Service:
def services(self) -> Dict[str, Service]:
return self.doc_gen.services

def expand_entity(self, entity):
return self.entities[entity]

def snippet(self, example: Example, readme_folder, api_name: str):
if self.lang_name not in example.languages:
return None
Expand Down

0 comments on commit f2e46f8

Please sign in to comment.