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'
937project = 'CppInterOp'
1038copyright = '2023, Vassil Vassilev'
11- author = 'Vassil Vassilev'
1239release = 'Dev'
1340
14- # -- General configuration ---------------------------------------------------
15- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
16-
41+ # sphinx config
1742extensions = []
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+ ]
2059exclude_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
2766html_theme = 'alabaster'
28-
2967html_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