1
- # noqa: D100
2
1
#!/usr/bin/env python3
3
2
#
4
3
# Mesa documentation build configuration file, created by
16
15
import os
17
16
import os .path as osp
18
17
import pathlib
19
- import sys
20
18
import string
19
+ import sys
21
20
from datetime import date
22
21
23
22
# If extensions (or modules to document with autodoc) are in another directory,
47
46
"sphinx.ext.viewcode" ,
48
47
"sphinx.ext.napoleon" , # for google style docstrings
49
48
"myst_nb" , # For Markdown and Jupyter notebooks
50
- "sphinx_copybutton" # For copying the code in the documentation
49
+ "sphinx_copybutton" , # For copying the code in the documentation
51
50
]
52
51
53
52
# Add any paths that contain templates here, relative to this directory.
131
130
# further. For a list of options available for each theme, see the
132
131
# documentation.
133
132
html_theme_options = {
134
- "navbar_start" : ["navbar-logo" , "version-switcher" ], # Show switcher in navbar
135
- "switcher" : {
136
- "json_url" : "https://mesa.readthedocs.io/latest/_static/switcher.json" , # URL of your switcher.json file
137
- "version_match" : version # Automatically matches the current version
138
- }
133
+ "navbar_start" : ["navbar-logo" ],
139
134
}
140
135
141
136
# Add any paths that contain custom themes here, relative to this directory.
177
172
178
173
# Custom sidebar templates, maps document names to template names.
179
174
html_sidebars = {
180
- ' migration_guide' : [], # No sidebar migration
175
+ " migration_guide" : [], # No sidebar migration
181
176
}
182
177
183
178
# Additional templates that should be rendered to pages, maps page names to
297
292
intersphinx_mapping = {"python" : ("https://docs.python.org/3" , None )}
298
293
299
294
300
-
301
- def write_example_md_file (agent_filename , model_filename , readme_filename , app_filename , md_filepath , template ):
295
+ def write_example_md_file (
296
+ agent_filename , model_filename , readme_filename , app_filename , md_filepath , template
297
+ ):
302
298
with open (agent_filename ) as content_file :
303
299
agent_file = content_file .read ()
304
300
with open (model_filename ) as content_file :
@@ -310,17 +306,30 @@ def write_example_md_file(agent_filename, model_filename, readme_filename, app_f
310
306
311
307
with open (md_filepath , "w" ) as fh :
312
308
content = template .substitute (
313
- dict (agent_file = agent_file , model_file = model_file ,
314
- readme_file = readme_file , app_file = app_file )
309
+ dict (
310
+ agent_file = agent_file ,
311
+ model_file = model_file ,
312
+ readme_file = readme_file ,
313
+ app_file = app_file ,
314
+ )
315
315
)
316
316
fh .write (content )
317
317
318
+
318
319
def setup_examples_pages ():
319
320
# create md files for all examples
320
321
# check what examples exist
321
322
examples_folder = osp .abspath (osp .join (HERE , ".." , "mesa" , "examples" ))
322
- basic_examples = [("basic" , f .path ) for f in os .scandir (osp .join (examples_folder , "basic" )) if f .is_dir () and not f .name .startswith ("__" ) ]
323
- advanced_examples = [("advanced" , f .path ) for f in os .scandir (osp .join (examples_folder , "advanced" )) if f .is_dir () and not f .name .startswith ("__" )]
323
+ basic_examples = [
324
+ ("basic" , f .path )
325
+ for f in os .scandir (osp .join (examples_folder , "basic" ))
326
+ if f .is_dir () and not f .name .startswith ("__" )
327
+ ]
328
+ advanced_examples = [
329
+ ("advanced" , f .path )
330
+ for f in os .scandir (osp .join (examples_folder , "advanced" ))
331
+ if f .is_dir () and not f .name .startswith ("__" )
332
+ ]
324
333
examples = basic_examples + advanced_examples
325
334
326
335
with open (os .path .join (HERE , "example_template.txt" )) as fh :
@@ -329,7 +338,9 @@ def setup_examples_pages():
329
338
root_folder = pathlib .Path (os .path .join (HERE , "examples" ))
330
339
root_folder .mkdir (parents = True , exist_ok = True )
331
340
pathlib .Path (os .path .join (root_folder , "basic" )).mkdir (parents = True , exist_ok = True )
332
- pathlib .Path (os .path .join (root_folder , "advanced" )).mkdir (parents = True , exist_ok = True )
341
+ pathlib .Path (os .path .join (root_folder , "advanced" )).mkdir (
342
+ parents = True , exist_ok = True
343
+ )
333
344
334
345
examples_md = []
335
346
for kind , example in examples :
@@ -344,7 +355,14 @@ def setup_examples_pages():
344
355
examples_md .append ((base_name , f"{ kind } /{ base_name } " ))
345
356
346
357
md_filepath = os .path .join (HERE , "examples" , kind , md_filename )
347
- write_example_md_file (agent_filename , model_filename , readme_filename , app_filename , md_filepath , template )
358
+ write_example_md_file (
359
+ agent_filename ,
360
+ model_filename ,
361
+ readme_filename ,
362
+ app_filename ,
363
+ md_filepath ,
364
+ template ,
365
+ )
348
366
349
367
# create overview of examples.md
350
368
with open (os .path .join (HERE , "examples_overview_template.txt" )) as fh :
@@ -357,14 +375,21 @@ def setup_examples_pages():
357
375
content = template .substitute (
358
376
dict (
359
377
readme = readme_md ,
360
- example_paths = "\n " .join ([f"{ ' ' .join (a .split ('_' ))} </examples/{ b } >" for a , b in examples_md ]),
378
+ example_paths = "\n " .join (
379
+ [
380
+ f"{ ' ' .join (a .split ('_' ))} </examples/{ b } >"
381
+ for a , b in examples_md
382
+ ]
383
+ ),
361
384
)
362
385
)
363
386
fh .write (content )
364
387
388
+
365
389
def setup (app ):
366
390
setup_examples_pages ()
367
391
392
+
368
393
#
369
394
if __name__ == "__main__" :
370
- setup_examples_pages ()
395
+ setup_examples_pages ()
0 commit comments