Skip to content

Commit 981ae03

Browse files
authored
Don't merge the config if not needed (#1536)
* Don't merge the config if not needed * Missing import
1 parent 2cd0734 commit 981ae03

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

voila/server_extension.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import gettext
1111
import os
12+
from typing import Optional
1213

1314
from jinja2 import Environment, FileSystemLoader
1415
from jupyter_server.base.handlers import FileFindHandler, path_regex
@@ -53,20 +54,24 @@ def _jupyter_server_extension_points():
5354
return [{"module": "voila.server_extension"}]
5455

5556

56-
def load_config_file() -> Config:
57+
def load_config_file() -> Optional[Config]:
5758
"""
5859
Loads voila.json and voila.py config file from current working
5960
directory and other Jupyter paths
6061
"""
6162

62-
new_config = Config()
63+
new_config = None
6364
base_file_name = "voila"
6465
config_file_paths = [*jupyter_config_path(), os.getcwd()]
6566

6667
for current in config_file_paths:
6768
py_loader = PyFileConfigLoader(filename=f"{base_file_name}.py", path=current)
6869
try:
6970
py_config = py_loader.load_config()
71+
72+
if new_config is None:
73+
new_config = Config()
74+
7075
new_config.merge(py_config)
7176
except ConfigFileNotFound:
7277
pass
@@ -76,6 +81,10 @@ def load_config_file() -> Config:
7681
)
7782
try:
7883
json_config = json_loader.load_config()
84+
85+
if new_config is None:
86+
new_config = Config()
87+
7988
new_config.merge(json_config)
8089
except ConfigFileNotFound:
8190
pass
@@ -88,7 +97,10 @@ def _load_jupyter_server_extension(server_app: ServerApp):
8897
# common configuration options between the server extension and the application
8998

9099
voila_configuration = VoilaConfiguration(parent=server_app)
91-
voila_configuration.config.merge(load_config_file())
100+
101+
local_config = load_config_file()
102+
if local_config is not None:
103+
voila_configuration.config.merge(load_config_file())
92104

93105
template_name = voila_configuration.template
94106
template_paths = collect_template_paths(["voila", "nbconvert"], template_name)

0 commit comments

Comments
 (0)