Browse Source

🔨 Update scripts to autofix changes in pre-commit

pull/14585/head
Sebastián Ramírez 7 months ago
parent
commit
6e8c1fa1ec
  1. 94
      scripts/docs.py

94
scripts/docs.py

@ -19,7 +19,13 @@ from slugify import slugify as py_slugify
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
SUPPORTED_LANGS = {"en", "de", "es", "pt", "ru"} SUPPORTED_LANGS = {
"en",
"de",
"es",
"pt",
"ru",
}
app = typer.Typer() app = typer.Typer()
@ -232,27 +238,15 @@ def generate_readme() -> None:
""" """
Generate README.md content from main index.md Generate README.md content from main index.md
""" """
typer.echo("Generating README")
readme_path = Path("README.md") readme_path = Path("README.md")
old_content = readme_path.read_text()
new_content = generate_readme_content() new_content = generate_readme_content()
readme_path.write_text(new_content, encoding="utf-8") if new_content != old_content:
print("README.md outdated from the latest index.md")
print("Updating README.md")
@app.command() readme_path.write_text(new_content, encoding="utf-8")
def verify_readme() -> None: raise typer.Exit(1)
""" print("README.md is up to date ✅")
Verify README.md content from main index.md
"""
typer.echo("Verifying README")
readme_path = Path("README.md")
generated_content = generate_readme_content()
readme_content = readme_path.read_text("utf-8")
if generated_content != readme_content:
typer.secho(
"README.md outdated from the latest index.md", color=typer.colors.RED
)
raise typer.Abort()
typer.echo("Valid README ✅")
@app.command() @app.command()
@ -280,7 +274,17 @@ def update_languages() -> None:
""" """
Update the mkdocs.yml file Languages section including all the available languages. Update the mkdocs.yml file Languages section including all the available languages.
""" """
update_config() old_config = get_en_config()
updated_config = get_updated_config_content()
if old_config != updated_config:
print("docs/en/mkdocs.yml outdated")
print("Updating docs/en/mkdocs.yml")
en_config_path.write_text(
yaml.dump(updated_config, sort_keys=False, width=200, allow_unicode=True),
encoding="utf-8",
)
raise typer.Exit(1)
print("docs/en/mkdocs.yml is up to date ✅")
@app.command() @app.command()
@ -367,39 +371,12 @@ def get_updated_config_content() -> dict[str, Any]:
return config return config
def update_config() -> None:
config = get_updated_config_content()
en_config_path.write_text(
yaml.dump(config, sort_keys=False, width=200, allow_unicode=True),
encoding="utf-8",
)
@app.command() @app.command()
def verify_config() -> None: def ensure_non_translated() -> None:
""" """
Verify main mkdocs.yml content to make sure it uses the latest language names. Ensure there are no files in the non translatable pages.
""" """
typer.echo("Verifying mkdocs.yml") print("Ensuring no non translated pages")
config = get_en_config()
updated_config = get_updated_config_content()
if config != updated_config:
typer.secho(
"docs/en/mkdocs.yml outdated from docs/language_names.yml, "
"update language_names.yml and run "
"python ./scripts/docs.py update-languages",
color=typer.colors.RED,
)
raise typer.Abort()
typer.echo("Valid mkdocs.yml ✅")
@app.command()
def verify_non_translated() -> None:
"""
Verify there are no files in the non translatable pages.
"""
print("Verifying non translated pages")
lang_paths = get_lang_paths() lang_paths = get_lang_paths()
error_paths = [] error_paths = []
for lang in lang_paths: for lang in lang_paths:
@ -410,20 +387,17 @@ def verify_non_translated() -> None:
if non_translatable_path.exists(): if non_translatable_path.exists():
error_paths.append(non_translatable_path) error_paths.append(non_translatable_path)
if error_paths: if error_paths:
print("Non-translated pages found, remove them:") print("Non-translated pages found, removing them:")
for error_path in error_paths: for error_path in error_paths:
print(error_path) print(error_path)
raise typer.Abort() if error_path.is_file():
error_path.unlink()
else:
shutil.rmtree(error_path)
raise typer.Exit(1)
print("No non-translated pages found ✅") print("No non-translated pages found ✅")
@app.command()
def verify_docs():
verify_readme()
verify_config()
verify_non_translated()
@app.command() @app.command()
def langs_json(): def langs_json():
langs = [] langs = []

Loading…
Cancel
Save