🔧 Update MkDocs configs and docs build setup (#900)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parent aa113fd · Browse files · 11 files·+144 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+144 added−28 removed
- other:+144 added−28 removed
Provenance
- Commit
0f4b07f- Tree
7ace52d- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
aa113fd
11 files changed+144 added−28 removed
modified:.github/workflows/build-docs.yml+3 added-6 removed
65 unmodified lines66676869707172717273747576737475767713 unmodified lines65 unmodified lines - uses: actions/cache@v4 with: key: mkdocs-cards-${{ github.ref }}-v1 path: .cache - name: Verify README run: python ./scripts/docs.py verify-readme - name: Build Docs if: github.event_name == 'pull_request' && github.secret_source != 'Actions' run: python -m mkdocs build - name: Build Docs with Insiders if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) run: python -m mkdocs build --config-file mkdocs.insiders.yml
run: python ./scripts/docs.py build - uses: actions/upload-artifact@v4 with: name: docs-site path: ./site/**13 unmodified linesmodified:docs/index.md+4 added
1+<style>2+.md-content .md-typeset h1 { display: none; }3+</style>4+5 <p align="center">6 <a href="https://typer.tiangolo.com"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" alt="Typer"></a>7 </p>8 <p align="center">377 unmodified linesdeleted:scripts/build-docs.sh-5 removed
12345#!/usr/bin/env bash
python -m mkdocs build
cp ./docs/index.md ./README.mddeleted:scripts/clean.sh-8 removed
12345678#!/bin/sh -e
if [ -d 'dist' ] ; then rm -r distfiif [ -d 'site' ] ; then rm -r sitefideleted:scripts/docs-live.sh-5 removed
12345#!/usr/bin/env bash
set -e
mkdocs serve --dev-addr 127.0.0.1:8008added:scripts/docs.py+130 added
1+import logging2+import os3+import re4+import subprocess5+from functools import lru_cache6+from http.server import HTTPServer, SimpleHTTPRequestHandler7+from importlib import metadata8+from pathlib import Path9+10+import mkdocs.commands.build11+import mkdocs.commands.serve12+import mkdocs.config13+import mkdocs.utils14+import typer15+16+logging.basicConfig(level=logging.INFO)17+18+mkdocs_name = "mkdocs.yml"19+en_docs_path = Path("")20+21+app = typer.Typer()22+23+24+@lru_cache25+def is_mkdocs_insiders() -> bool:26+ version = metadata.version("mkdocs-material")27+ return "insiders" in version28+29+30+@app.callback()31+def callback() -> None:32+ if is_mkdocs_insiders():33+ os.environ["INSIDERS_FILE"] = "./mkdocs.insiders.yml"34+ # For MacOS with insiders and Cairo35+ os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = "/opt/homebrew/lib"36+37+38+def generate_readme_content() -> str:39+ en_index = en_docs_path / "docs" / "index.md"40+ content = en_index.read_text("utf-8")41+ match_pre = re.search(r"</style>\n\n", content)42+ if not match_pre:43+ raise RuntimeError("Couldn't find pre section (<style>) in index.md")44+ frontmatter_end = match_pre.end()45+ new_content = content[frontmatter_end:]46+ return new_content47+48+49+@app.command()50+def generate_readme() -> None:51+ """52+ Generate README.md content from main index.md53+ """54+ typer.echo("Generating README")55+ readme_path = Path("README.md")56+ new_content = generate_readme_content()57+ readme_path.write_text(new_content, encoding="utf-8")58+59+60+@app.command()61+def verify_readme() -> None:62+ """63+ Verify README.md content from main index.md64+ """65+ typer.echo("Verifying README")66+ readme_path = Path("README.md")67+ generated_content = generate_readme_content()68+ readme_content = readme_path.read_text("utf-8")69+ if generated_content != readme_content:70+ typer.secho(71+ "README.md outdated from the latest index.md", color=typer.colors.RED72+ )73+ raise typer.Abort()74+ typer.echo("Valid README ✅")75+76+77+@app.command()78+def live() -> None:79+ """80+ Serve with livereload a docs site for a specific language.81+82+ This only shows the actual translated files, not the placeholders created with83+ build-all.84+85+ Takes an optional LANG argument with the name of the language to serve, by default86+ en.87+ """88+ # Enable line numbers during local development to make it easier to highlight89+ os.environ["LINENUMS"] = "true"90+ mkdocs.commands.serve.serve(dev_addr="127.0.0.1:8008")91+92+93+@app.command()94+def build() -> None:95+ """96+ Build the docs.97+ """98+ insiders_env_file = os.environ.get("INSIDERS_FILE")99+ print(f"Insiders file {insiders_env_file}")100+ if is_mkdocs_insiders():101+ print("Using insiders")102+ print("Building docs")103+ subprocess.run(["mkdocs", "build"], check=True)104+ typer.secho("Successfully built docs", color=typer.colors.GREEN)105+106+107+@app.command()108+def serve() -> None:109+ """110+ A quick server to preview a built site.111+112+ For development, prefer the command live (or just mkdocs serve).113+114+ This is here only to preview the documentation site.115+116+ Make sure you run the build command first.117+ """118+ typer.echo("Warning: this is a very simple server.")119+ typer.echo("For development, use the command live instead.")120+ typer.echo("This is here only to preview the documentation site.")121+ typer.echo("Make sure you run the build command first.")122+ os.chdir("site")123+ server_address = ("", 8008)124+ server = HTTPServer(server_address, SimpleHTTPRequestHandler)125+ typer.echo("Serving at: http://127.0.0.1:8008")126+ server.serve_forever()127+128+129+if __name__ == "__main__":130+ app()modified:scripts/test-files.sh-2 removed
1234567678#!/usr/bin/env bash
set -eset -x
# Check README.md is up to datediff --brief docs/index.md README.md# Check copy paste errors in tutorialsif grep -r --include "*.md" "Usage: tutorial" ./docs ; then echo "Incorrect console demo"; exit 1 ; fiif grep -r --include "*.md" "python tutorial" ./docs ; then echo "Incorrect console demo"; exit 1 ; fimodified:mkdocs.insiders.yml-1 removed
1123INHERIT: mkdocs.ymlplugins: social: typeset:added:mkdocs.maybe-insiders.yml+6 added
123456# Define this here and not in the main mkdocs.yml file because that one could be auto# updated and written, and the script would remove the env varINHERIT: !ENV [INSIDERS_FILE, './mkdocs.no-insiders.yml']markdown_extensions: pymdownx.highlight: linenums: !ENV [LINENUMS, false]added:mkdocs.no-insiders.yml
modified:mkdocs.yml+1 added-1 removed
1+INHERIT: ./mkdocs.maybe-insiders.yml2 site_name: Typer3 site_description: Typer, build great CLIs. Easy to code. Based on Python type hints.4 site_url: https://typer.tiangolo.com/5 130 unmodified lines136 - css/termynal.css137 - css/custom.css138 139 extra_javascript:139- - https://unpkg.com/mermaid@8.4.6/dist/mermaid.min.js140 - js/termynal.js141 - js/custom.js