Skip to content

Commit 94d9686

Browse files
authored
Add docs PR preview
1 parent 1c3f884 commit 94d9686

File tree

3 files changed

+129
-33
lines changed

3 files changed

+129
-33
lines changed

.github/workflows/rtd-preview.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: RTD Preview
2+
on:
3+
pull_request_target:
4+
types: [opened]
5+
6+
permissions:
7+
pull-requests: write
8+
9+
jobs:
10+
binder:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Comment on the PR with the RTD preview
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{secrets.GITHUB_TOKEN}}
17+
script: |
18+
var PR_NUMBER = context.issue.number
19+
github.rest.issues.createComment({
20+
issue_number: context.issue.number,
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
body: `https://jupyterlite--${PR_NUMBER}.org.readthedocs.build/en/${PR_NUMBER}/_static/lab/index.html :point_left: Try it on ReadTheDocs`
24+
})

.readthedocs.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ build:
88
os: "ubuntu-22.04"
99
tools:
1010
python: "3.11"
11+
jobs:
12+
pre_build:
13+
- doit -n4 setup
14+
- doit -n4 build
15+
- doit -n4 docs:typedoc:mystify
16+
- doit -n4 docs:app:pack
17+
- doit -n4 dist
18+
sphinx:
19+
builder: html
20+
configuration: docs/conf.py
21+
fail_on_warning: true
1122
apt_packages:
1223
- clang-13
1324
- cmake

docs/conf.py

Lines changed: 94 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,118 @@
1-
# Configuration file for the Sphinx documentation builder.
2-
#
3-
# For the full list of built-in configuration values, see the documentation:
4-
# https://www.sphinx-doc.org/en/master/usage/configuration.html
1+
highlight_language = "C++"
2+
3+
todo_include_todos = True
54

6-
# -- Project information -----------------------------------------------------
7-
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
5+
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
6+
7+
# Add latex physics package
8+
mathjax3_config = {
9+
"loader": {"load": ["[tex]/physics"]},
10+
"tex": {"packages": {"[+]": ["physics"]}},
11+
}
812

13+
"""documentation for CppInterOp"""
14+
import datetime
15+
import json
16+
import os
17+
import subprocess
18+
import sys
19+
from pathlib import Path
20+
21+
from sphinx.application import Sphinx
22+
23+
os.environ.update(IN_SPHINX="1")
24+
25+
CONF_PY = Path(__file__)
26+
HERE = CONF_PY.parent
27+
ROOT = HERE.parent
28+
RTD = json.loads(os.environ.get("READTHEDOCS", "False").lower())
29+
30+
# tasks that won't have been run prior to building the docs on RTD
31+
RTD_PRE_TASKS = ["build", "docs:typedoc:mystify", "docs:app:pack"]
32+
33+
RTD_POST_TASKS = ["docs:post:schema", "docs:post:images"]
34+
35+
# metadata
36+
author = 'Vassil Vassilev'
937
project = 'CppInterOp'
1038
copyright = '2023, Vassil Vassilev'
11-
author = 'Vassil Vassilev'
1239
release = 'Dev'
1340

14-
# -- General configuration ---------------------------------------------------
15-
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
16-
41+
# sphinx config
1742
extensions = []
1843

19-
templates_path = ['_templates']
44+
autosectionlabel_prefix_document = True
45+
myst_heading_anchors = 3
46+
suppress_warnings = ["autosectionlabel.*"]
47+
48+
# files
49+
templates_path = ["_templates"]
50+
# rely on the order of these to patch json, labextensions correctly
51+
html_static_path = [
52+
# docs stuff
53+
"_static",
54+
# as-built assets for testing "hot" downstreams against a PR without rebuilding
55+
"../dist",
56+
# as-built application, extensions, contents, and patched jupyter-lite.json
57+
"../build/docs-app",
58+
]
2059
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
2160

61+
html_css_files = [
62+
"doxygen.css",
63+
]
2264

23-
24-
# -- Options for HTML output -------------------------------------------------
25-
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
26-
65+
# theme
2766
html_theme = 'alabaster'
28-
2967
html_theme_options = {
3068
"github_user": "compiler-research",
3169
"github_repo": "CppInterOp",
3270
"github_banner": True,
3371
"fixed_sidebar": True,
3472
}
3573

36-
highlight_language = "C++"
74+
html_context = {
75+
"github_user": "compiler-research",
76+
"github_repo": "CppInterOp",
77+
"github_version": "main",
78+
"doc_path": "docs",
79+
}
3780

38-
todo_include_todos = True
3981

40-
mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"
82+
def do_tasks(label, tasks):
83+
"""Run some doit tasks before/after the build"""
84+
task_rcs = []
4185

42-
# Add latex physics package
43-
mathjax3_config = {
44-
"loader": {"load": ["[tex]/physics"]},
45-
"tex": {"packages": {"[+]": ["physics"]}},
46-
}
86+
for task in tasks:
87+
print(f"[CppInterOp-docs] running {label} {task}", flush=True)
88+
rc = subprocess.call(["doit", "-n4", task], cwd=str(ROOT))
4789

48-
import os
49-
CPPINTEROP_ROOT = os.path.abspath('..')
50-
html_extra_path = [CPPINTEROP_ROOT + '/build/docs/']
90+
if rc != 0:
91+
rc = subprocess.call(["doit", task], cwd=str(ROOT))
5192

52-
import subprocess
53-
command = 'mkdir {0}/build; cd {0}/build; cmake ../ -DClang_DIR=/usr/lib/llvm-13/build/lib/cmake/clang\
54-
-DLLVM_DIR=/usr/lib/llvm-13/build/lib/cmake/llvm -DCPPINTEROP_ENABLE_DOXYGEN=ON\
55-
-DCPPINTEROP_INCLUDE_DOCS=ON'.format(CPPINTEROP_ROOT)
56-
subprocess.call(command, shell=True)
57-
subprocess.call('doxygen {0}/build/docs/doxygen.cfg'.format(CPPINTEROP_ROOT), shell=True)
93+
print(f"[CppInterOp-docs] ... ran {label} {task}: returned {rc}", flush=True)
94+
task_rcs += [rc]
95+
96+
if max(task_rcs) > 0:
97+
raise Exception("[CppInterOp-docs] ... FAIL, see log above")
98+
99+
print(f"[CppInterOp-docs] ... {label.upper()} OK", flush=True)
100+
101+
102+
def before_rtd_build(app: Sphinx, error):
103+
"""ensure doit docs:sphinx precursors have been met on RTD"""
104+
print("[CppInterOp-docs] Staging files changed by RTD...", flush=True)
105+
subprocess.call(["git", "add", "."], cwd=str(ROOT))
106+
do_tasks("post", RTD_PRE_TASKS)
107+
108+
109+
def after_build(app: Sphinx, error):
110+
"""sphinx-jsonschema makes duplicate ids. clean them"""
111+
os.environ.update(JLITE_DOCS_OUT=app.builder.outdir) #
112+
do_tasks("post", RTD_POST_TASKS)
113+
114+
115+
def setup(app):
116+
app.connect("build-finished", after_build)
117+
if RTD:
118+
app.connect("config-inited", before_rtd_build)

0 commit comments

Comments
 (0)