@@ -116,93 +116,14 @@ def cleanup_nb(nb):
116
116
pass
117
117
118
118
119
- def get_kernel ():
120
- """Find the kernel name for your python version"""
121
- return 'python%s' % sys .version_info .major
122
-
123
-
124
- def execute_nb (src , dst , allow_errors = False , timeout = 1000 , kernel_name = '' ):
125
- """
126
- Execute notebook in `src` and write the output to `dst`
127
-
128
- Parameters
129
- ----------
130
- src, dst: str
131
- path to notebook
132
- allow_errors: bool
133
- timeout: int
134
- kernel_name: str
135
- defualts to value set in notebook metadata
136
-
137
- Returns
138
- -------
139
- dst: str
140
- """
141
- import nbformat
142
- from nbconvert .preprocessors import ExecutePreprocessor
143
-
144
- with io .open (src , encoding = 'utf-8' ) as f :
145
- nb = nbformat .read (f , as_version = 4 )
146
-
147
- ep = ExecutePreprocessor (allow_errors = allow_errors ,
148
- timeout = timeout ,
149
- kernel_name = kernel_name )
150
- ep .preprocess (nb , resources = {})
151
-
152
- with io .open (dst , 'wt' , encoding = 'utf-8' ) as f :
153
- nbformat .write (nb , f )
154
- return dst
155
-
156
-
157
- def convert_nb (src , dst , to = 'html' , template_file = 'basic' ):
158
- """
159
- Convert a notebook `src`.
160
-
161
- Parameters
162
- ----------
163
- src, dst: str
164
- filepaths
165
- to: {'rst', 'html'}
166
- format to export to
167
- template_file: str
168
- name of template file to use. Default 'basic'
169
- """
170
- from nbconvert import HTMLExporter , RSTExporter
171
-
172
- dispatch = {'rst' : RSTExporter , 'html' : HTMLExporter }
173
- exporter = dispatch [to .lower ()](template_file = template_file )
174
-
175
- (body , resources ) = exporter .from_filename (src )
176
- with io .open (dst , 'wt' , encoding = 'utf-8' ) as f :
177
- f .write (body )
178
- return dst
179
-
180
-
181
119
def html ():
182
120
check_build ()
183
121
184
- notebooks = [
185
- 'source/html-styling.ipynb' ,
186
- ]
187
-
188
- for nb in notebooks :
189
- with cleanup_nb (nb ):
190
- try :
191
- print ("Converting %s" % nb )
192
- kernel_name = get_kernel ()
193
- executed = execute_nb (nb , nb + '.executed' , allow_errors = True ,
194
- kernel_name = kernel_name )
195
- convert_nb (executed , nb .rstrip ('.ipynb' ) + '.html' )
196
- except (ImportError , IndexError ) as e :
197
- print (e )
198
- print ("Failed to convert %s" % nb )
199
-
200
122
if os .system ('sphinx-build -P -b html -d build/doctrees '
201
123
'source build/html' ):
202
124
raise SystemExit ("Building HTML failed." )
203
125
try :
204
126
# remove stale file
205
- os .remove ('source/html-styling.html' )
206
127
os .remove ('build/html/pandas.zip' )
207
128
except :
208
129
pass
0 commit comments