Browse Source

🔨 Update scripts and pre-commit to autofix files (#14585)

pull/14591/head
Sebastián Ramírez 7 months ago
committed by GitHub
parent
commit
b9b2793bda
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      .github/workflows/build-docs.yml
  2. 22
      .pre-commit-config.yaml
  3. 94
      scripts/docs.py

2
.github/workflows/build-docs.yml

@ -60,8 +60,6 @@ jobs:
pyproject.toml pyproject.toml
- name: Install docs extras - name: Install docs extras
run: uv pip install -r requirements-docs.txt run: uv pip install -r requirements-docs.txt
- name: Verify Docs
run: python ./scripts/docs.py verify-docs
- name: Export Language Codes - name: Export Language Codes
id: show-langs id: show-langs
run: | run: |

22
.pre-commit-config.yaml

@ -21,10 +21,28 @@ repos:
- id: ruff-format - id: ruff-format
- repo: local - repo: local
hooks: hooks:
- id: local-script - id: add-permalinks-pages
language: unsupported language: unsupported
name: local script name: add-permalinks-pages
entry: uv run ./scripts/docs.py add-permalinks-pages entry: uv run ./scripts/docs.py add-permalinks-pages
args: args:
- --update-existing - --update-existing
files: ^docs/en/docs/.*\.md$ files: ^docs/en/docs/.*\.md$
- id: generate-readme
language: unsupported
name: generate README.md from index.md
entry: uv run ./scripts/docs.py generate-readme
files: ^docs/en/docs/index\.md|docs/en/data/sponsors\.yml|scripts/docs\.py$
pass_filenames: false
- id: update-languages
language: unsupported
name: update languages
entry: uv run ./scripts/docs.py update-languages
files: ^docs/.*|scripts/docs\.py$
pass_filenames: false
- id: ensure-non-translated
language: unsupported
name: ensure non-translated files are not modified
entry: uv run ./scripts/docs.py ensure-non-translated
files: ^docs/(?!en/).*|^scripts/docs\.py$
pass_filenames: false

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