1111# documentation root, use os.path.abspath to make it absolute, like shown here.
1212#
1313import os
14+ from pathlib import Path
1415from m2r import MdInclude
1516from recommonmark .transform import AutoStructify
1617
2526release = version
2627
2728# HTML icons
28- html_logo = "img/{}.svg" .format (project )
29- html_favicon = "img/{}.ico" .format (project )
29+ img_path = 'img'
30+ html_logo = img_path + "/labscript_32nx32n.svg"
31+ html_favicon = img_path + "/labscript.ico"
3032
3133# -- General configuration (should be identical across all projects) ------------------
3234
8991}
9092
9193# list of all labscript suite components that have docs
92- labscript_suite_programs = [
93- 'labscript' ,
94- 'runmanager' ,
95- 'runviewer' ,
96- 'blacs' ,
97- 'lyse' ,
98- 'labscript-utils' ,
99- 'labscript-devices' ,
100- ]
101- # remove this current repo from the list
102- if project in labscript_suite_programs :
103- labscript_suite_programs .remove (project )
94+ labscript_suite_programs = {
95+ 'labscript' : {
96+ 'desc' : 'Expressive composition of hardware-timed experiments' ,
97+ 'img' : img_path + '/labscript_32nx32n.svg' ,
98+ 'type' : 'lib' ,
99+ },
100+ 'labscript-devices' : {
101+ 'desc' : 'Plugin architecture for controlling experiment hardware' ,
102+ 'img' : img_path + '/labscript_32nx32n.svg' ,
103+ 'type' : 'lib' ,
104+ },
105+ 'labscript-utils' : {
106+ 'desc' : 'Shared modules used by the *labscript suite*' ,
107+ 'img' : img_path + '/labscript_32nx32n.svg' ,
108+ 'type' : 'lib' ,
109+ },
110+ 'runmanager' : {
111+ 'desc' : 'Graphical and remote interface to parameterized experiments' ,
112+ 'img' : img_path + '/runmanager_32nx32n.svg' ,
113+ 'type' : 'gui' ,
114+ },
115+ 'blacs' : {
116+ 'desc' : 'Graphical interface to scientific instruments and experiment supervision' ,
117+ 'img' : img_path + '/blacs_32nx32n.svg' ,
118+ 'type' : 'gui' ,
119+ },
120+ 'lyse' : {
121+ 'desc' : 'Online analysis of live experiment data' ,
122+ 'img' : img_path + '/lyse_32nx32n.svg' ,
123+ 'type' : 'gui' ,
124+ },
125+ 'runviewer' : {
126+ 'desc' : 'Visualize hardware-timed experiment instructions' ,
127+ 'img' : img_path + '/runviewer_32nx32n.svg' ,
128+ 'type' : 'gui' ,
129+ },
130+ }
104131
105132# whether to use stable or latest version
106133labscript_suite_doc_version = os .environ .get ('READTHEDOCS_VERSION' , 'latest' )
110137# add intersphinx references for each component
111138for ls_prog in labscript_suite_programs :
112139 intersphinx_mapping [ls_prog ] = (
113- 'https://docs.labscript_suite .org/projects/{}/en/{}/' .format (
140+ 'https://docs.labscriptsuite .org/projects/{}/en/{}/' .format (
114141 ls_prog , labscript_suite_doc_version
115142 ),
116143 None ,
119146# add intersphinx reference for the metapackage
120147if project != "the labscript suite" :
121148 intersphinx_mapping ['labscript-suite' ] = (
122- 'https://docs.labscript_suite .org/en/{}/' .format (labscript_suite_doc_version ),
149+ 'https://docs.labscriptsuite .org/en/{}/' .format (labscript_suite_doc_version ),
123150 None ,
124151 )
125152
143170# The theme to use for HTML and HTML Help pages. See the documentation for
144171# a list of builtin themes.
145172#
146- # html_theme = 'alabaster'
147173html_theme = "sphinx_rtd_theme"
148174html_title = "labscript suite | {project}" .format (
149175 project = project
160186# Customize the html_theme
161187html_theme_options = {'navigation_depth' : 3 }
162188
189+ # Template for generating the components.rst file
190+ # fmt:off
191+ components_rst_template = \
192+ """
193+ {metapackage_toctree}
194+
195+ *labscript suite* components
196+ ============================
197+
198+ The *labscript suite* is modular by design, and is comprised of:
199+
200+ .. list-table:: Python libraries
201+ :widths: 10 90
202+ :header-rows: 0
203+
204+ {lib}
205+
206+ .. list-table:: Graphical applications
207+ :widths: 10 90
208+ :header-rows: 0
209+
210+ {gui}
211+
212+ .. toctree::
213+ :maxdepth: 2
214+ :hidden:
215+
216+ {toctree_entires}
217+
218+ {rst_defs}
219+ """
220+
221+ components_rst_table_template = \
222+ """ * - .. image:: {img}
223+ :target: {target}
224+ :class: labscript-suite-icon
225+ - |{prog}|_ --- {desc}
226+ """
227+
228+ components_rst_link_template = \
229+ """.. |{prog}| replace:: **{prog}**
230+ .. _{prog}: {target}
231+ """
232+
233+ components_rst_metapackage_template = \
234+ """.. toctree::
235+ :maxdepth: 2
236+ :hidden:
237+
238+ Metapackage documentation <{}>
239+ """
240+ # fmt:on
163241
164242# Use m2r only for mdinclude and recommonmark for everything else
165243# https://github.com/readthedocs/recommonmark/issues/191#issuecomment-622369992
@@ -180,21 +258,45 @@ def setup(app):
180258 app .add_directive ('mdinclude' , MdInclude )
181259 app .add_stylesheet ('custom.css' )
182260
183- with open (
184- os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'component_docs.rst' ),
185- 'w' ,
186- ) as f :
187- f .write ("labscript suite components\n " )
188- f .write ("==========================\n " )
189- f .write (" \n " )
190- f .write (".. toctree::\n " )
191- f .write (" :maxdepth: 2\n " )
192- f .write (" \n " )
193- if project != "the labscript suite" :
194- f .write (
195- " labscript suite (metapackage)<{}>\n " .format (
196- intersphinx_mapping ['labscript-suite' ][0 ]
197- )
261+ # generate the components.rst file dynamically so it points to stable/latest
262+ # of subprojects correctly
263+ components_rst_table = {
264+ "lib" : "" ,
265+ "gui" : "" ,
266+ }
267+ components_rst_link = ""
268+ components_rst_toctree = ""
269+ components_rst_metapackage = ""
270+ if project != 'the labscript suite' :
271+ components_rst_metapackage = components_rst_metapackage_template .format (
272+ intersphinx_mapping ['labscript-suite' ][0 ]
273+ )
274+ metapackage_img = img_path + "/labscript-suite-rectangular-transparent_138nx70n.svg"
275+ for ls_prog , data in labscript_suite_programs .items ():
276+ components_rst_table [data ['type' ]] += components_rst_table_template .format (
277+ prog = ls_prog ,
278+ labscript_suite_doc_version = labscript_suite_doc_version ,
279+ target = intersphinx_mapping [ls_prog ][0 ],
280+ ** data
281+ )
282+ components_rst_link += components_rst_link_template .format (
283+ prog = ls_prog ,
284+ labscript_suite_doc_version = labscript_suite_doc_version ,
285+ target = intersphinx_mapping [ls_prog ][0 ],
286+ )
287+ for ls_prog in sorted (labscript_suite_programs ):
288+ if ls_prog != project :
289+ components_rst_toctree += " {} <{}>\n " .format (
290+ ls_prog , intersphinx_mapping [ls_prog ][0 ]
198291 )
199- for ls_prog in labscript_suite_programs :
200- f .write (" {} <{}>\n " .format (ls_prog , intersphinx_mapping [ls_prog ][0 ]))
292+
293+ components_rst = components_rst_template .format (
294+ toctree_entires = components_rst_toctree ,
295+ rst_defs = components_rst_link ,
296+ labscript_suite_doc_version = labscript_suite_doc_version ,
297+ metapackage_toctree = components_rst_metapackage ,
298+ ** components_rst_table
299+ )
300+
301+ with open (Path (__file__ ).resolve ().parent / 'components.rst' , 'w' ) as f :
302+ f .write (components_rst )
0 commit comments