Skip to content

Commit 8a9d348

Browse files
authored
Fix the --expose-app-in-browser and --custom-css CLI flags (#8060)
1 parent 1c37cc5 commit 8a9d348

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎notebook/app.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ExtensionHandlerJinjaMixin,
1515
ExtensionHandlerMixin,
1616
)
17-
from jupyter_server.serverapp import flags
17+
from jupyter_server.serverapp import ServerApp, flags
1818
from jupyter_server.utils import url_escape, url_is_absolute
1919
from jupyter_server.utils import url_path_join as ujoin
2020
from jupyterlab.commands import (
@@ -355,6 +355,16 @@ def initialize_handlers(self) -> None:
355355
self.handlers.append(("/custom/custom.css", CustomCssHandler))
356356
super().initialize_handlers()
357357

358+
@classmethod
359+
def make_serverapp(cls, **kwargs: t.Any) -> ServerApp:
360+
"""
361+
Add the notebook flags to the server that parses the command line,
362+
because jupyter_server merges only the extension aliases.
363+
"""
364+
serverapp = super().make_serverapp(**kwargs)
365+
serverapp.flags.update(cls.flags) # type:ignore[arg-type]
366+
return serverapp
367+
358368
def initialize(self, argv: list[str] | None = None) -> None: # noqa: ARG002
359369
"""Subclass because the ExtensionApp.initialize() method does not take arguments"""
360370
super().initialize()

‎tests/test_app.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
import pytest
4+
from jupyter_server.serverapp import ServerApp
45
from jupyter_server.serverapp import flags as serverapp_flags
56
from tornado.httpclient import HTTPClientError
67

@@ -27,6 +28,17 @@ def test_notebook_app_flags_are_isolated():
2728
assert notebook_flags.isdisjoint(serverapp_flags)
2829

2930

31+
def test_notebook_app_flags_reach_serverapp():
32+
ServerApp.clear_instance()
33+
try:
34+
serverapp = JupyterNotebookApp.make_serverapp()
35+
serverapp.parse_command_line(["--expose-app-in-browser", "--custom-css"])
36+
assert serverapp.config.JupyterNotebookApp.expose_app_in_browser is True
37+
assert serverapp.config.JupyterNotebookApp.custom_css is True
38+
finally:
39+
ServerApp.clear_instance()
40+
41+
3042
async def test_notebook_handler(notebooks, jp_fetch):
3143
for nbpath in notebooks:
3244
r = await jp_fetch("/", nbpath)

0 commit comments

Comments
 (0)