diff --git a/.readthedocs.yml b/.readthedocs.yml index 60724f36e..5bea859a7 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -3,11 +3,9 @@ version: 2 build: - os: ubuntu-22.04 - tools: - python: "3.12" + os: ubuntu-24.04 commands: - asdf plugin add uv - asdf install uv latest - asdf global uv latest - - NO_COLOR=1 uv run --no-dev --group docs mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html + - NO_COLOR=1 uv run -p 3.14 --no-dev --group docs mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html diff --git a/docs/main.py b/docs/main.py index 15d42cbb1..9766726a1 100644 --- a/docs/main.py +++ b/docs/main.py @@ -1,8 +1,12 @@ import os +import re import subprocess import sysconfig from typing import Any +import rich.console +import rich.text + def define_env(env: Any) -> None: "Hook function for mkdocs-macros" @@ -12,5 +16,13 @@ def subprocess_run(*args: str) -> str: "Run a subprocess and return the stdout" env = os.environ.copy() scripts = sysconfig.get_path("scripts") + env.pop("NO_COLOR", None) env["PATH"] = f"{scripts}{os.pathsep}{env.get('PATH', '')}" - return subprocess.run(args, check=True, capture_output=True, text=True, env=env).stdout + env["PYTHON_COLORS"] = "1" + output = subprocess.run(args, check=True, capture_output=True, text=True, env=env).stdout + rich_text = rich.text.Text.from_ansi(output) + console = rich.console.Console(record=True) + console.print(rich_text) + page = console.export_html(inline_styles=True) + text = re.search(r"(.*?)", page, re.DOTALL | re.IGNORECASE).group(1) + return text.strip() diff --git a/docs/options.md b/docs/options.md index 3bd90369f..353400b1d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1692,9 +1692,7 @@ Platform-specific environment variables are also available:
### Options -```text « subprocess_run("cibuildwheel", "--help") » -``` ### Return codes diff --git a/pyproject.toml b/pyproject.toml index cb5ae27a6..6972fc56b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,6 +76,7 @@ docs = [ "mkdocs-macros-plugin", "mkdocs==1.6.1", "pymdown-extensions", + "rich", ] test = [ "build",