Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore some traits in shim layer #38

Merged
merged 2 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions nbclassic/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,28 @@ class NotebookApp(
traits.NotebookAppTraits,
):

name = 'jupyter-nbclassic'
name = 'notebook'
version = __version__
description = _("""The Jupyter HTML Notebook.

This launches a Tornado based HTML Notebook Server that serves up an HTML5/Javascript Notebook client.""")

name = 'nbclassic'

aliases = aliases
flags = flags
extension_url = "/tree"

# Override the default open_Browser trait in ExtensionApp,
# setting it to True.
open_browser = Bool(
True,
help="""Whether to open in a browser after starting.
The specific browser used is platform dependent and
determined by the python standard library `webbrowser`
module, unless it is overridden using the --browser
(ServerApp.browser) configuration option.
"""
).tag(config=True)

static_custom_path = List(Unicode(),
help=_("""Path to search for custom.js, css""")
)
Expand Down Expand Up @@ -215,7 +225,7 @@ def initialize_handlers(self):
handlers.extend(load_handlers('nbclassic.tree.handlers'))
handlers.extend(load_handlers('nbclassic.notebook.handlers'))
handlers.extend(load_handlers('nbclassic.edit.handlers'))

# Add terminal handlers
handlers.append(
(r"/terminals/(\w+)", TerminalHandler)
Expand Down
25 changes: 16 additions & 9 deletions nbclassic/shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

EXTAPP_AND_NBAPP_AND_SVAPP_SHIM_MSG = lambda trait_name, extapp_name: (
"'{trait_name}' is found in {extapp_name}, NotebookApp, "
"and ServerApp. This is a recent change."
"and ServerApp. This is a recent change. "
"This config will only be set in {extapp_name}. "
"Please check if you should also config these traits in "
"NotebookApp and ServerApp for your purpose.".format(
Expand All @@ -47,7 +47,7 @@

EXTAPP_AND_SVAPP_SHIM_MSG = lambda trait_name, extapp_name: (
"'{trait_name}' is found in both {extapp_name} "
"and ServerApp. This is a recent change."
"and ServerApp. This is a recent change. "
"This config will only be set in {extapp_name}. "
"Please check if you should also config these traits in "
"ServerApp for your purpose.".format(
Expand All @@ -58,7 +58,7 @@

EXTAPP_AND_NBAPP_SHIM_MSG = lambda trait_name, extapp_name: (
"'{trait_name}' is found in both {extapp_name} "
"and NotebookApp. This is a recent change."
"and NotebookApp. This is a recent change. "
"This config will only be set in {extapp_name}. "
"Please check if you should also config these traits in "
"NotebookApp for your purpose.".format(
Expand All @@ -70,7 +70,7 @@
NOT_EXTAPP_NBAPP_AND_SVAPP_SHIM_MSG = lambda trait_name, extapp_name: (
"'{trait_name}' is not found in {extapp_name}, but "
"it was found in both NotebookApp "
"and ServerApp. This is likely a recent change."
"and ServerApp. This is likely a recent change. "
"This config will only be set in ServerApp. "
"Please check if you should also config these traits in "
"NotebookApp for your purpose.".format(
Expand All @@ -97,6 +97,9 @@
)
)

# A tuple of traits that shouldn't be shimmed or throw any
# warnings of any kind.
IGNORED_TRAITS = ("open_browser", "log_level", "log_format")


class NBClassicConfigShimMixin:
Expand Down Expand Up @@ -129,7 +132,6 @@ class NBClassicConfigShimMixin:
read the docstring under `shim_config_from_notebook_to_jupyter_server`.
"""


@wraps(JupyterApp.update_config)
def update_config(self, config):
# Shim traits to handle transition from NotebookApp to ServerApp
Expand Down Expand Up @@ -211,7 +213,10 @@ def shim_config_from_notebook_to_jupyter_server(self, config):
for trait_name, trait_value in nbapp_config.items():
in_svapp = trait_name in svapp_traits
in_nbapp = trait_name in nbapp_traits
if in_svapp and in_nbapp:
if trait_name in IGNORED_TRAITS:
# Pass trait through without any warning message.
nbapp_config_shim.update({trait_name: trait_value})
elif in_svapp and in_nbapp:
warning_msg = NBAPP_AND_SVAPP_SHIM_MSG(trait_name)
nbapp_config_shim.update({trait_name: trait_value})
elif in_svapp:
Expand All @@ -232,8 +237,10 @@ def shim_config_from_notebook_to_jupyter_server(self, config):
in_extapp = trait_name in extapp_traits
in_svapp = trait_name in svapp_traits
in_nbapp = trait_name in nbapp_traits

if all([in_extapp, in_svapp, in_nbapp]):
if trait_name in IGNORED_TRAITS:
# Pass trait through without any warning message.
extapp_config_shim.update({trait_name: trait_value})
elif all([in_extapp, in_svapp, in_nbapp]):
warning_msg = EXTAPP_AND_NBAPP_AND_SVAPP_SHIM_MSG(
trait_name,
extapp_name
Expand Down Expand Up @@ -289,4 +296,4 @@ def shim_config_from_notebook_to_jupyter_server(self, config):
}))
# Update the full config with new values
config_shim.update(new_config)
return config_shim
return config_shim
2 changes: 1 addition & 1 deletion tests/shim/test_nbclassic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def jp_server_config():

@pytest.fixture
def nbclassic(jp_serverapp):
return jp_serverapp.extension_manager.extension_points["nbclassic"].app
return jp_serverapp.extension_manager.extension_points["notebook"].app


def list_test_params(param_input):
Expand Down