Skip to content

Commit a6c82b3

Browse files
Added code to add extensions if using DoxyRest
1 parent c92a5cb commit a6c82b3

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

docs/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ function(_setup_sphinx)
9898
set(SPHINX_OUTPUT_DIR ${DOC_OUTPUT_DIR}/docs)
9999
set(SPHINX_INDEX_FILE ${SPHINX_OUTPUT_DIR}/index.html)
100100

101+
set(SPHINX_CONF_IN ${SPHINX_SOURCE}/conf.py.in)
102+
set(SPHINX_CONF_OUT ${SPHINX_SOURCE}/conf.py)
103+
101104
if(DPCTL_ENABLE_DOXYREST)
102105
set(DEPEND_ON_DOXYREST "Doxyrest")
103106
endif()
@@ -120,7 +123,7 @@ function(_setup_sphinx)
120123
${SPHINX_INDEX_FILE}
121124
)
122125
# Create a conf.py by replacing variables inside @@ with the current values
123-
# configure_file(${SPHINX_CONF_IN} ${SPHINX_CONF_OUT} @ONLY)
126+
configure_file(${SPHINX_CONF_IN} ${SPHINX_CONF_OUT} @ONLY)
124127
endfunction()
125128

126129
function(_set_current_release)

docs/doc_sources/conf.py renamed to docs/doc_sources/conf.py.in

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,37 @@
3737
"sphinx.ext.todo",
3838
"sphinx.ext.viewcode",
3939
"sphinxcontrib.programoutput",
40-
# "sphinxcontrib.googleanalytics",
40+
"sphinxcontrib.googleanalytics",
4141
"sphinx_design",
4242
]
4343

44+
googleanalytics_id = 'G-7TCKS5BHYE'
45+
googleanalytics_enabled = True
46+
47+
todo_include_todos = True
48+
use_doxyrest = "@DPCTL_ENABLE_DOXYREST@"
49+
50+
if use_doxyrest == "ON":
51+
# Specify the path to Doxyrest extensions for Sphinx:
52+
import os
53+
import sys
54+
55+
sys.path.insert(
56+
1,
57+
os.path.abspath("@DOXYREST_SPHINX_DIR@"),
58+
)
59+
extensions += ["doxyrest", "cpplexer"]
60+
# A workaround to fix issues leftover in the doxyrest generated
61+
# rst files.
62+
import fileinput
63+
64+
with fileinput.FileInput(
65+
"@DOXYREST_OUTPUT_DIR@/global.rst", inplace=True
66+
) as file:
67+
for line in file:
68+
print(line.replace("typedefDPCTL_C_EXTERN_C_BEGIN", ""), end="")
69+
70+
4471
templates_path = ["_templates"]
4572
exclude_patterns = []
4673

@@ -82,3 +109,44 @@
82109
"numba_dpex": ("https://intelpython.github.io/numba-dpex/latest/", None),
83110
"cython": ("https://docs.cython.org/en/latest/", None),
84111
}
112+
113+
# When the cmake DPCTL_USE_MULTIVERSION_TEMPLATE flag is set we generate
114+
# links in the sidebar to the documentation for older versions of dpctl.
115+
# Note that this option does not actually generate the documentation for
116+
# older versions, it only adds links in the sidebar to earlier versions of
117+
# the documentation. All earlier versions of the documentation should be
118+
# generated and pushed to the gh-pages branch manually, after which the
119+
# doc_versions.txt should be updated.
120+
121+
generate_multiversion = "@DPCTL_USE_MULTIVERSION_TEMPLATE@"
122+
123+
if generate_multiversion == "ON":
124+
try:
125+
html_context
126+
except NameError:
127+
html_context = dict()
128+
html_context["display_lower_left"] = True
129+
templates_path = ["_templates"]
130+
html_context["current_version"] = version
131+
html_context["version"] = version
132+
133+
# POPULATE LINKS TO OTHER VERSIONS
134+
html_context["versions"] = list()
135+
136+
# Populate the list of documented versions from the doc_versions.tx
137+
versions = []
138+
with open("doc_versions.txt", "r") as doc_versions:
139+
while True:
140+
version = doc_versions.readline().strip()
141+
if not version:
142+
break
143+
elif len(version):
144+
versions.append(version)
145+
146+
# FIXME: Remove this hard coding
147+
DOC_SITE_NAME = "https://intelpython.github.io/dpctl/"
148+
149+
for version in versions:
150+
html_context["versions"].append(
151+
(version, DOC_SITE_NAME + version + "/index.html")
152+
)

0 commit comments

Comments
 (0)