Skip to content

Commit c90acce

Browse files
docs: color output for docs (#2407)
* docs: color output for docs Signed-off-by: Henry Schreiner <[email protected]> * fix: use asdf (python-build) * docs: try to fix colors Signed-off-by: Henry Schreiner <[email protected]> * Update .pre-commit-config.yaml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2346c5f commit c90acce

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ repos:
8787
- id: check-github-actions
8888
- id: check-github-workflows
8989
- id: check-gitlab-ci
90-
- id: check-readthedocs
90+
# Disabled due to schema issue for now:
91+
# - id: check-readthedocs
9192
- id: check-travis
9293
- id: check-jsonschema
9394
name: Check projects

.readthedocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
version: 2
44

55
build:
6-
os: ubuntu-22.04
7-
tools:
8-
python: "3.12"
6+
os: ubuntu-24.04
97
commands:
8+
- asdf install python 3.14-dev
9+
- asdf global python 3.14-dev
1010
- asdf plugin add uv
1111
- asdf install uv latest
1212
- asdf global uv latest

docs/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import os
2+
import re
23
import subprocess
34
import sysconfig
45
from typing import Any
56

7+
import rich.console
8+
import rich.text
9+
610

711
def define_env(env: Any) -> None:
812
"Hook function for mkdocs-macros"
@@ -12,5 +16,15 @@ def subprocess_run(*args: str) -> str:
1216
"Run a subprocess and return the stdout"
1317
env = os.environ.copy()
1418
scripts = sysconfig.get_path("scripts")
19+
env.pop("NO_COLOR", None)
1520
env["PATH"] = f"{scripts}{os.pathsep}{env.get('PATH', '')}"
16-
return subprocess.run(args, check=True, capture_output=True, text=True, env=env).stdout
21+
env["PYTHON_COLORS"] = "1"
22+
output = subprocess.run(args, check=True, capture_output=True, text=True, env=env).stdout
23+
rich_text = rich.text.Text.from_ansi(output)
24+
console = rich.console.Console(record=True, force_terminal=True)
25+
console.print(rich_text)
26+
page = console.export_html(inline_styles=True)
27+
result = re.search(r"<body.*?>(.*?)</body>", page, re.DOTALL | re.IGNORECASE)
28+
assert result
29+
txt = result.group(1).strip()
30+
return txt.replace("code ", 'code class="nohighlight" ')

docs/options.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,9 +1714,7 @@ Platform-specific environment variables are also available:<br/>
17141714

17151715
### Options
17161716

1717-
```text
17181717
« subprocess_run("cibuildwheel", "--help") »
1719-
```
17201718

17211719
### Return codes
17221720

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def bump_version(session: nox.Session) -> None:
173173
session.install_and_run_script("bin/bump_version.py")
174174

175175

176-
@nox.session(default=False, python="3.12")
176+
@nox.session(default=False)
177177
def docs(session: nox.Session) -> None:
178178
"""
179179
Build the docs. Will serve unless --non-interactive

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ docs = [
7676
"mkdocs-macros-plugin",
7777
"mkdocs==1.6.1",
7878
"pymdown-extensions",
79+
"rich",
7980
]
8081
test = [
8182
"build",

0 commit comments

Comments
 (0)