1
- import os
1
+ import os , sys
2
2
from sphinx .application import Sphinx
3
3
4
4
# -- Project information -----------------------------------------------------
8
8
9
9
# -- General configuration ---------------------------------------------------
10
10
11
+ sys .path .insert (0 , os .path .abspath ("../sphinxext" ))
12
+
11
13
# Add any Sphinx extension module names here, as strings. They can be
12
14
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
13
15
# ones.
23
25
"sphinx_codeautolink" ,
24
26
"notfound.extension" ,
25
27
"sphinx_gallery.load_style" ,
28
+ "gallery_generator" ,
26
29
]
27
30
28
31
# List of patterns, relative to source directory, that match files and
@@ -46,22 +49,19 @@ def hack_nbsphinx(app: Sphinx) -> None:
46
49
GalleryNode ,
47
50
NbGallery ,
48
51
patched_toctree_resolve ,
49
- NotebookParser ,
50
- NbInput ,
51
- NbOutput ,
52
- NbInfo ,
53
- NbWarning ,
54
- CodeAreaNode ,
55
- depart_codearea_html ,
56
- visit_codearea_latex ,
57
- depart_codearea_latex ,
58
- GetSizeFromImages ,
59
52
)
60
53
from sphinx .environment .adapters import toctree
61
54
62
- nbsphinx_thumbnails = {
63
- "case_studies/stochastic_volatility" : "_static/stochastic_volatility.png" ,
64
- }
55
+ from glob import glob
56
+
57
+ nb_paths = glob ("examples/*/*.ipynb" )
58
+ nbsphinx_thumbnails = {}
59
+ for nb_path in nb_paths :
60
+ png_file = os .path .join ("_static" , os .path .splitext (os .path .split (nb_path )[- 1 ])[0 ] + ".png" )
61
+ nb_path_rel = os .path .splitext (
62
+ os .path .join (* os .path .normpath (nb_path ).split (os .path .sep )[1 :])
63
+ )[0 ]
64
+ nbsphinx_thumbnails [nb_path_rel ] = png_file
65
65
66
66
def builder_inited (app : Sphinx ):
67
67
if not hasattr (app .env , "nbsphinx_thumbnails" ):
@@ -70,46 +70,6 @@ def builder_inited(app: Sphinx):
70
70
def do_nothing (* node ):
71
71
pass
72
72
73
- app .add_source_parser (NotebookParser )
74
- # app.add_config_value('nbsphinx_execute', 'auto', rebuild='env')
75
- app .add_config_value ("nbsphinx_kernel_name" , "" , rebuild = "env" )
76
- app .add_config_value ("nbsphinx_execute_arguments" , [], rebuild = "env" )
77
- app .add_config_value ("nbsphinx_allow_errors" , False , rebuild = "" )
78
- app .add_config_value ("nbsphinx_timeout" , None , rebuild = "" )
79
- app .add_config_value ("nbsphinx_codecell_lexer" , "none" , rebuild = "env" )
80
- app .add_config_value ("nbsphinx_prompt_width" , "4.5ex" , rebuild = "html" )
81
- app .add_config_value ("nbsphinx_responsive_width" , "540px" , rebuild = "html" )
82
- app .add_config_value ("nbsphinx_prolog" , None , rebuild = "env" )
83
- app .add_config_value ("nbsphinx_epilog" , None , rebuild = "env" )
84
- app .add_config_value ("nbsphinx_input_prompt" , "[%s]:" , rebuild = "env" )
85
- app .add_config_value ("nbsphinx_output_prompt" , "[%s]:" , rebuild = "env" )
86
- app .add_config_value ("nbsphinx_custom_formats" , {}, rebuild = "env" )
87
- # Default value is set in config_inited():
88
- app .add_config_value ("nbsphinx_requirejs_path" , None , rebuild = "html" )
89
- # Default value is set in config_inited():
90
- app .add_config_value ("nbsphinx_requirejs_options" , None , rebuild = "html" )
91
- # This will be updated in env_updated():
92
- app .add_config_value ("nbsphinx_widgets_path" , None , rebuild = "html" )
93
- app .add_config_value ("nbsphinx_widgets_options" , {}, rebuild = "html" )
94
- # app.add_config_value('nbsphinx_thumbnails', {}, rebuild='html')
95
- app .add_config_value ("nbsphinx_assume_equations" , True , rebuild = "env" )
96
-
97
- app .add_directive ("nbinput" , NbInput )
98
- app .add_directive ("nboutput" , NbOutput )
99
- app .add_directive ("nbinfo" , NbInfo )
100
- app .add_directive ("nbwarning" , NbWarning )
101
- app .add_directive ("nbgallery" , NbGallery )
102
- app .add_node (
103
- CodeAreaNode ,
104
- html = (do_nothing , depart_codearea_html ),
105
- latex = (visit_codearea_latex , depart_codearea_latex ),
106
- text = (do_nothing , do_nothing ),
107
- )
108
- app .connect ("builder-inited" , builder_inited )
109
- app .connect ("doctree-resolved" , doctree_resolved )
110
- app .add_post_transform (GetSizeFromImages )
111
-
112
- app .add_config_value ("nbsphinx_execute" , "auto" , rebuild = "env" )
113
73
app .add_config_value ("nbsphinx_thumbnails" , nbsphinx_thumbnails , rebuild = "html" )
114
74
app .add_directive ("nbgallery" , NbGallery )
115
75
app .add_node (
@@ -185,7 +145,7 @@ def setup(app: Sphinx):
185
145
# Add any paths that contain custom static files (such as style sheets) here,
186
146
# relative to this directory. They are copied after the builtin static files,
187
147
# so a file named "default.css" will overwrite the builtin "default.css".
188
- html_static_path = ["../_static" , "../thumbnails " ]
148
+ html_static_path = ["../_static" , "../_images" , "../_templates " ]
189
149
html_css_files = ["custom.css" ]
190
150
templates_path = ["../_templates" ]
191
151
html_sidebars = {
0 commit comments