Skip to content

Commit b7afe82

Browse files
committed
restore observer on root_dir
this flag prevents deprecated `notebook_dir` config from having higher priority than newer config
1 parent bc828c5 commit b7afe82

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

jupyter_server/serverapp.py

+7
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,13 @@ def _root_dir_validate(self, proposal):
16751675
raise TraitError(trans.gettext("No such directory: '%r'") % value)
16761676
return value
16771677

1678+
@observe("root_dir")
1679+
def _root_dir_changed(self, change):
1680+
# record that root_dir is set,
1681+
# which affects loading of deprecated notebook_dir
1682+
self._root_dir_set = True
1683+
pass
1684+
16781685
preferred_dir = Unicode(
16791686
config=True,
16801687
help=trans.gettext("Preferred starting directory to use for notebooks and kernels."),

tests/test_serverapp.py

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99
from jupyter_core.application import NoStart
1010
from traitlets import TraitError
11+
from traitlets.config import Config
1112
from traitlets.tests.utils import check_help_all_output
1213

1314
from jupyter_server.auth.security import passwd_check
@@ -542,3 +543,21 @@ def test_browser_open_files(jp_configurable_serverapp, should_exist, caplog):
542543
url = urljoin("file:", pathname2url(app.browser_open_file))
543544
url_messages = [rec.message for rec in caplog.records if url in rec.message]
544545
assert url_messages if should_exist else not url_messages
546+
547+
548+
def test_deprecated_notebook_dir_priority(jp_configurable_serverapp, tmp_path):
549+
notebook_dir = tmp_path / "notebook"
550+
notebook_dir.mkdir()
551+
cli_dir = tmp_path / "cli"
552+
cli_dir.mkdir()
553+
554+
app = jp_configurable_serverapp(argv=[str(cli_dir)], root_dir=None)
555+
assert app._root_dir_set
556+
557+
# simulate delayed loading of notebook_dir config
558+
# this should _not_ take priority over an explicitly set root_dir
559+
# as done by notebook_shim
560+
cfg = Config()
561+
cfg.ServerApp.notebook_dir = str(notebook_dir)
562+
app.update_config(cfg)
563+
assert app.root_dir == str(cli_dir)

0 commit comments

Comments
 (0)