Skip to content

docs: color output for docs #2407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 1, 2025
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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ repos:
- id: check-github-actions
- id: check-github-workflows
- id: check-gitlab-ci
- id: check-readthedocs
# Disabled due to schema issue for now:
# - id: check-readthedocs
- id: check-travis
- id: check-jsonschema
name: Check projects
Expand Down
6 changes: 3 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.12"
os: ubuntu-24.04
commands:
- asdf install python 3.14-dev
- asdf global python 3.14-dev
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
Expand Down
16 changes: 15 additions & 1 deletion docs/main.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,5 +16,15 @@ 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, force_terminal=True)
console.print(rich_text)
page = console.export_html(inline_styles=True)
result = re.search(r"<body.*?>(.*?)</body>", page, re.DOTALL | re.IGNORECASE)
assert result
txt = result.group(1).strip()
return txt.replace("code ", 'code class="nohighlight" ')
2 changes: 0 additions & 2 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1714,9 +1714,7 @@ Platform-specific environment variables are also available:<br/>

### Options

```text
« subprocess_run("cibuildwheel", "--help") »
```

### Return codes

Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def bump_version(session: nox.Session) -> None:
session.install_and_run_script("bin/bump_version.py")


@nox.session(default=False, python="3.12")
@nox.session(default=False)
def docs(session: nox.Session) -> None:
"""
Build the docs. Will serve unless --non-interactive
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ docs = [
"mkdocs-macros-plugin",
"mkdocs==1.6.1",
"pymdown-extensions",
"rich",
]
test = [
"build",
Expand Down