Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ jobs:
pyproject.toml
- name: Install docs extras
run: uv pip install -r requirements-docs.txt
- name: Verify Docs
run: python ./scripts/docs.py verify-docs
- name: Export Language Codes
id: show-langs
run: |
Expand Down
22 changes: 20 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,28 @@ repos:
- id: ruff-format
- repo: local
hooks:
- id: local-script
- id: add-permalinks-pages
language: unsupported
name: local script
name: add-permalinks-pages
entry: uv run ./scripts/docs.py add-permalinks-pages
args:
- --update-existing
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 changes: 34 additions & 60 deletions scripts/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@

logging.basicConfig(level=logging.INFO)

SUPPORTED_LANGS = {"en", "de", "es", "pt", "ru"}
SUPPORTED_LANGS = {
"en",
"de",
"es",
"pt",
"ru",
}


app = typer.Typer()
Expand Down Expand Up @@ -232,27 +238,15 @@ def generate_readme() -> None:
"""
Generate README.md content from main index.md
"""
typer.echo("Generating README")
readme_path = Path("README.md")
old_content = readme_path.read_text()
new_content = generate_readme_content()
readme_path.write_text(new_content, encoding="utf-8")


@app.command()
def verify_readme() -> None:
"""
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 βœ…")
if new_content != old_content:
print("README.md outdated from the latest index.md")
print("Updating README.md")
readme_path.write_text(new_content, encoding="utf-8")
raise typer.Exit(1)
print("README.md is up to date βœ…")


@app.command()
Expand Down Expand Up @@ -280,7 +274,17 @@ def update_languages() -> None:
"""
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()
Expand Down Expand Up @@ -367,39 +371,12 @@ def get_updated_config_content() -> dict[str, Any]:
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()
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")
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")
print("Ensuring no non translated pages")
lang_paths = get_lang_paths()
error_paths = []
for lang in lang_paths:
Expand All @@ -410,20 +387,17 @@ def verify_non_translated() -> None:
if non_translatable_path.exists():
error_paths.append(non_translatable_path)
if error_paths:
print("Non-translated pages found, remove them:")
print("Non-translated pages found, removing them:")
for error_path in error_paths:
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 βœ…")


@app.command()
def verify_docs():
verify_readme()
verify_config()
verify_non_translated()


@app.command()
def langs_json():
langs = []
Expand Down
Loading