3
3
import logging
4
4
import os
5
5
import shutil
6
- from copy import deepcopy
7
6
from pathlib import Path
8
7
from typing import Dict
9
8
from typing import List as TypeList
@@ -67,6 +66,7 @@ class Voilite(Application):
67
66
'theme' : 'VoilaConfiguration.theme' ,
68
67
'base_url' : 'Voilite.base_url' ,
69
68
'contents' : 'Voilite.contents' ,
69
+ 'packages' : 'Voilite.packages' ,
70
70
}
71
71
72
72
output_prefix = Unicode (
@@ -79,6 +79,16 @@ class Voilite(Application):
79
79
'files' , config = True , help = _ ('Name of the user contents directory' )
80
80
)
81
81
82
+ packages = List (
83
+ [],
84
+ config = True ,
85
+ help = _ ('List of packages to be installed in the voilite enviroment' ),
86
+ )
87
+
88
+ config_file_paths = List (
89
+ Unicode (), config = True , help = _ ('Paths to search for voilite.(py|json)' )
90
+ )
91
+
82
92
@default ('log_level' )
83
93
def _default_log_level (self ):
84
94
return logging .INFO
@@ -90,6 +100,10 @@ def _default_root_dir(self):
90
100
else :
91
101
return os .getcwd ()
92
102
103
+ @default ('config_file_paths' )
104
+ def _config_file_paths_default (self ):
105
+ return [os .getcwd ()]
106
+
93
107
def setup_template_dirs (self ):
94
108
if self .voilite_configuration .template :
95
109
template_name = self .voilite_configuration .template
@@ -147,6 +161,7 @@ def initialize(self, argv=None):
147
161
raise ValueError (
148
162
'provided more than 1 argument: %r' % self .extra_args
149
163
)
164
+ self .load_config_file ('voilite' , path = self .config_file_paths )
150
165
self .voilite_configuration = VoilaConfiguration (parent = self )
151
166
self .setup_template_dirs ()
152
167
@@ -196,7 +211,8 @@ def ignore_func(dir, files: TypeList[str]) -> TypeList[str]:
196
211
return [
197
212
f
198
213
for f in files
199
- if os .path .isfile (os .path .join (dir , f )) and f .endswith ('voila.js' )
214
+ if os .path .isfile (os .path .join (dir , f ))
215
+ and f .endswith ('voila.js' )
200
216
]
201
217
202
218
for root in self .static_paths :
@@ -267,31 +283,29 @@ def convert_notebook(
267
283
nb_path : str ,
268
284
page_config : Dict ,
269
285
output_prefix : str ,
286
+ packages : TypeList [str ],
270
287
output_name : str = None ,
271
288
) -> None :
272
289
nb_name = output_name
273
290
274
291
nb_path = Path (nb_path )
275
292
if not nb_name :
276
293
nb_name = f'{ nb_path .stem } .html'
277
-
278
- page_config_copy = deepcopy (page_config )
279
-
280
294
with open (nb_path ) as f :
281
295
nb = nbformat .read (f , 4 )
282
- src = [
296
+ nb_src = [
283
297
{
284
298
'cell_source' : cell ['source' ],
285
299
'cell_type' : cell ['cell_type' ],
286
300
}
287
301
for cell in nb ['cells' ]
288
302
]
289
- page_config_copy ['notebookSrc' ] = src
290
-
291
303
voilite_exporter = VoiliteExporter (
292
304
voilite_config = self .voilite_configuration ,
293
- page_config = page_config_copy ,
305
+ page_config = page_config ,
294
306
base_url = self .base_url ,
307
+ nb_src = nb_src ,
308
+ packages = packages ,
295
309
)
296
310
content , _ = voilite_exporter .from_filename (nb_path )
297
311
output_dir = os .path .join (output_prefix , nb_path .parent )
@@ -317,6 +331,7 @@ def convert_directory(self, page_config):
317
331
nb ,
318
332
page_config ,
319
333
os .path .join (self .output_prefix , 'voila' , 'render' ),
334
+ self .packages ,
320
335
)
321
336
322
337
def start (self ):
@@ -347,6 +362,7 @@ def start(self):
347
362
self .notebook_path ,
348
363
page_config ,
349
364
self .output_prefix ,
365
+ self .packages ,
350
366
'index.html' ,
351
367
)
352
368
else :
0 commit comments