14
14
from jupyter_server .base .handlers import FileFindHandler , path_regex
15
15
from jupyter_server .utils import url_path_join
16
16
from jupyterlab_server .themes_handler import ThemesHandler
17
-
17
+ from jupyter_core .paths import jupyter_config_path
18
+ from jupyter_server .serverapp import ServerApp
18
19
from .tornado .contentshandler import VoilaContentsHandler
19
-
20
+ from traitlets .config import (
21
+ JSONFileConfigLoader ,
22
+ PyFileConfigLoader ,
23
+ Config ,
24
+ ConfigFileNotFound ,
25
+ )
20
26
from .configuration import VoilaConfiguration
21
27
from .tornado .handler import TornadoVoilaHandler
22
28
from .paths import ROOT , collect_static_paths , collect_template_paths , jupyter_path
@@ -38,10 +44,44 @@ def _jupyter_server_extension_points():
38
44
return [{"module" : "voila.server_extension" }]
39
45
40
46
41
- def _load_jupyter_server_extension (server_app ):
47
+ def load_config_file () -> Config :
48
+ """
49
+ Loads voila.json and voila.py config file from current working
50
+ directory and other Jupyter paths
51
+ """
52
+
53
+ new_config = Config ()
54
+ base_file_name = "voila"
55
+ config_file_paths = [* jupyter_config_path (), os .getcwd ()]
56
+
57
+ for current in config_file_paths :
58
+ py_loader = PyFileConfigLoader (filename = f"{ base_file_name } .py" , path = current )
59
+ try :
60
+ py_config = py_loader .load_config ()
61
+ new_config .merge (py_config )
62
+ except ConfigFileNotFound :
63
+ pass
64
+
65
+ json_loader = JSONFileConfigLoader (
66
+ filename = f"{ base_file_name } .json" , path = current
67
+ )
68
+ try :
69
+ json_config = json_loader .load_config ()
70
+ new_config .merge (json_config )
71
+ except ConfigFileNotFound :
72
+ pass
73
+
74
+ return new_config
75
+
76
+
77
+ def _load_jupyter_server_extension (server_app : ServerApp ):
42
78
web_app = server_app .web_app
43
79
# common configuration options between the server extension and the application
44
- voila_configuration = VoilaConfiguration (parent = server_app )
80
+
81
+ voila_configuration = VoilaConfiguration (
82
+ parent = server_app , config = load_config_file ()
83
+ )
84
+
45
85
template_name = voila_configuration .template
46
86
template_paths = collect_template_paths (["voila" , "nbconvert" ], template_name )
47
87
static_paths = collect_static_paths (["voila" , "nbconvert" ], template_name )
0 commit comments