8
8
from sphinx .util .fileutil import copy_asset
9
9
from IPython .lib .lexers import IPythonTracebackLexer , IPython3Lexer
10
10
11
- from .ast import JupyterCell , JupyterCellNode , JupyterWidgetViewNode , JupyterWidgetStateNode , WIDGET_VIEW_MIMETYPE , jupyter_download_role
11
+ from .ast import (
12
+ JupyterCell ,
13
+ JupyterCellNode ,
14
+ JupyterWidgetViewNode ,
15
+ JupyterWidgetStateNode ,
16
+ WIDGET_VIEW_MIMETYPE ,
17
+ jupyter_download_role ,
18
+ )
12
19
from .execute import JupyterKernelNode , JupyterKernel , ExecuteJupyterCells
13
20
from .thebelab import ThebeButton , ThebeButtonNode , ThebeOutputNode , ThebeSourceNode
14
21
15
- REQUIRE_URL_DEFAULT = 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js'
16
- THEBELAB_URL_DEFAULT = 'https://unpkg.com/thebelab@^0.4.0'
22
+ REQUIRE_URL_DEFAULT = (
23
+ "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
24
+ )
25
+ THEBELAB_URL_DEFAULT = "https://unpkg.com/thebelab@^0.4.0"
17
26
18
27
logger = logging .getLogger (__name__ )
19
28
@@ -27,36 +36,42 @@ def builder_inited(app):
27
36
require_url = app .config .jupyter_sphinx_require_url
28
37
if require_url :
29
38
app .add_js_file (require_url )
30
- embed_url = app .config .jupyter_sphinx_embed_url or ipywidgets .embed .DEFAULT_EMBED_REQUIREJS_URL
39
+ embed_url = (
40
+ app .config .jupyter_sphinx_embed_url
41
+ or ipywidgets .embed .DEFAULT_EMBED_REQUIREJS_URL
42
+ )
31
43
else :
32
- embed_url = app .config .jupyter_sphinx_embed_url or ipywidgets .embed .DEFAULT_EMBED_SCRIPT_URL
44
+ embed_url = (
45
+ app .config .jupyter_sphinx_embed_url
46
+ or ipywidgets .embed .DEFAULT_EMBED_SCRIPT_URL
47
+ )
33
48
if embed_url :
34
49
app .add_js_file (embed_url )
35
50
36
51
# add jupyter-sphinx css
37
- app .add_css_file (' jupyter-sphinx.css' )
52
+ app .add_css_file (" jupyter-sphinx.css" )
38
53
# Check if a thebelab config was specified
39
54
if app .config .jupyter_sphinx_thebelab_config :
40
- app .add_js_file (' thebelab-helper.js' )
41
- app .add_css_file (' thebelab.css' )
55
+ app .add_js_file (" thebelab-helper.js" )
56
+ app .add_css_file (" thebelab.css" )
42
57
43
58
44
59
def build_finished (app , env ):
45
- if app .builder .format != ' html' :
60
+ if app .builder .format != " html" :
46
61
return
47
62
48
63
# Copy stylesheet
49
- src = os .path .join (os .path .dirname (__file__ ), ' css' )
50
- dst = os .path .join (app .outdir , ' _static' )
64
+ src = os .path .join (os .path .dirname (__file__ ), " css" )
65
+ dst = os .path .join (app .outdir , " _static" )
51
66
copy_asset (src , dst )
52
67
53
68
thebe_config = app .config .jupyter_sphinx_thebelab_config
54
69
if not thebe_config :
55
70
return
56
71
57
72
# Copy all thebelab related assets
58
- src = os .path .join (os .path .dirname (__file__ ), ' thebelab' )
59
- dst = os .path .join (app .outdir , ' _static' )
73
+ src = os .path .join (os .path .dirname (__file__ ), " thebelab" )
74
+ dst = os .path .join (app .outdir , " _static" )
60
75
copy_asset (src , dst )
61
76
62
77
@@ -69,42 +84,38 @@ def _setup(app):
69
84
# Configuration
70
85
71
86
app .add_config_value (
72
- ' jupyter_execute_kwargs' ,
87
+ " jupyter_execute_kwargs" ,
73
88
dict (timeout = - 1 , allow_errors = True , store_widget_state = True ),
74
- ' env'
89
+ " env" ,
75
90
)
91
+ app .add_config_value ("jupyter_execute_default_kernel" , "python3" , "env" )
76
92
app .add_config_value (
77
- 'jupyter_execute_default_kernel' ,
78
- 'python3' ,
79
- 'env'
80
- )
81
- app .add_config_value (
82
- 'jupyter_execute_data_priority' ,
93
+ "jupyter_execute_data_priority" ,
83
94
[
84
95
WIDGET_VIEW_MIMETYPE ,
85
- ' application/javascript' ,
86
- ' text/html' ,
87
- ' image/svg+xml' ,
88
- ' image/png' ,
89
- ' image/jpeg' ,
90
- ' text/latex' ,
91
- ' text/plain'
96
+ " application/javascript" ,
97
+ " text/html" ,
98
+ " image/svg+xml" ,
99
+ " image/png" ,
100
+ " image/jpeg" ,
101
+ " text/latex" ,
102
+ " text/plain" ,
92
103
],
93
- ' env' ,
104
+ " env" ,
94
105
)
95
106
96
107
# ipywidgets config
97
- app .add_config_value (' jupyter_sphinx_require_url' , REQUIRE_URL_DEFAULT , ' html' )
98
- app .add_config_value (' jupyter_sphinx_embed_url' , None , ' html' )
108
+ app .add_config_value (" jupyter_sphinx_require_url" , REQUIRE_URL_DEFAULT , " html" )
109
+ app .add_config_value (" jupyter_sphinx_embed_url" , None , " html" )
99
110
100
111
# thebelab config, can be either a filename or a dict
101
- app .add_config_value (' jupyter_sphinx_thebelab_config' , None , ' html' )
112
+ app .add_config_value (" jupyter_sphinx_thebelab_config" , None , " html" )
102
113
103
- app .add_config_value (' jupyter_sphinx_thebelab_url' , THEBELAB_URL_DEFAULT , ' html' )
114
+ app .add_config_value (" jupyter_sphinx_thebelab_url" , THEBELAB_URL_DEFAULT , " html" )
104
115
105
116
# linenos config
106
- app .add_config_value (' jupyter_sphinx_linenos' , False , ' env' )
107
- app .add_config_value (' jupyter_sphinx_continue_linenos' , False , ' env' )
117
+ app .add_config_value (" jupyter_sphinx_linenos" , False , " env" )
118
+ app .add_config_value (" jupyter_sphinx_continue_linenos" , False , " env" )
108
119
109
120
# Used for nodes that do not need to be rendered
110
121
def skip (self , node ):
@@ -132,17 +143,16 @@ def visit_element_html(self, node):
132
143
133
144
# Used to render the ThebeSourceNode conditionally for non-HTML builders
134
145
def visit_thebe_source (self , node ):
135
- if node [' hide_code' ]:
146
+ if node [" hide_code" ]:
136
147
raise docutils .nodes .SkipNode
137
148
else :
138
149
self .visit_container (node )
139
150
140
151
render_thebe_source = (
141
152
visit_thebe_source ,
142
- lambda self , node : self .depart_container (node )
153
+ lambda self , node : self .depart_container (node ),
143
154
)
144
155
145
-
146
156
# JupyterKernelNode is just a doctree marker for the
147
157
# ExecuteJupyterCells transform, so we don't actually render it.
148
158
app .add_node (
@@ -220,24 +230,21 @@ def visit_thebe_source(self, node):
220
230
man = (skip , None ),
221
231
)
222
232
223
- app .add_directive (' jupyter-execute' , JupyterCell )
224
- app .add_directive (' jupyter-kernel' , JupyterKernel )
225
- app .add_directive (' thebe-button' , ThebeButton )
226
- app .add_role (' jupyter-download:notebook' , jupyter_download_role )
227
- app .add_role (' jupyter-download:script' , jupyter_download_role )
233
+ app .add_directive (" jupyter-execute" , JupyterCell )
234
+ app .add_directive (" jupyter-kernel" , JupyterKernel )
235
+ app .add_directive (" thebe-button" , ThebeButton )
236
+ app .add_role (" jupyter-download:notebook" , jupyter_download_role )
237
+ app .add_role (" jupyter-download:script" , jupyter_download_role )
228
238
app .add_transform (ExecuteJupyterCells )
229
239
230
240
# For syntax highlighting
231
- app .add_lexer (' ipythontb' , IPythonTracebackLexer ())
232
- app .add_lexer (' ipython' , IPython3Lexer ())
241
+ app .add_lexer (" ipythontb" , IPythonTracebackLexer ())
242
+ app .add_lexer (" ipython" , IPython3Lexer ())
233
243
234
- app .connect (' builder-inited' , builder_inited )
235
- app .connect (' build-finished' , build_finished )
244
+ app .connect (" builder-inited" , builder_inited )
245
+ app .connect (" build-finished" , build_finished )
236
246
237
- return {
238
- 'version' : __version__ ,
239
- 'parallel_read_safe' : True ,
240
- }
247
+ return {"version" : __version__ , "parallel_read_safe" : True }
241
248
242
249
243
250
def setup (app ):
@@ -246,4 +253,4 @@ def setup(app):
246
253
This should be replaced with `_setup` after a deprecation cycle.
247
254
"""
248
255
out = _setup (app )
249
- return out
256
+ return out
0 commit comments