Skip to content

feat(readme_generator): don't hardcode the list of languages, extract it from the README templates #2105

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 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tools/readme_generator/make_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from copy import deepcopy

from typing import Dict, Optional, List
from typing import Dict, Optional, List, Tuple

import toml
from jinja2 import Environment, FileSystemLoader
Expand Down Expand Up @@ -51,7 +51,22 @@ def generate_READMEs(app_path: Path):

env = Environment(loader=FileSystemLoader(Path(__file__).parent / "templates"))

for lang, lang_suffix in [("en", ""), ("fr", "_fr")]:
# parse available README template and generate a list in the form of:
# > [("en", ""), ("fr", "_fr"), ...]
available_langs: List[Tuple[str, str]] = [("en", "")]
for README_template in (Path(__file__).parent / "templates").iterdir():
# we only want README_{lang}.md.j2 files
if README_template.name == "README.md.j2":
continue

if not README_template.name.endswith(".j2") or not README_template.name.startswith("README_"):
continue

language_code = README_template.name.split("_")[1].split(".")[0]

available_langs.append((language_code, "_" + language_code))

for lang, lang_suffix in available_langs:
template = env.get_template(f"README{lang_suffix}.md.j2")

if (app_path / "doc" / f"DESCRIPTION{lang_suffix}.md").exists():
Expand Down