Skip to content

Commit 5dc20a3

Browse files
authored
Merge pull request #392 from afshin/contents-manager
Enable notebook ContentsManager in jupyter_server
2 parents 2477da6 + 7978e46 commit 5dc20a3

File tree

5 files changed

+478
-4
lines changed

5 files changed

+478
-4
lines changed

.github/workflows/python-windows.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ jobs:
4444
pip check
4545
- name: Run the tests
4646
run: |
47-
pytest -vv
47+
# Disable capturing (-s) output from Pytest on Windows.
48+
# For an unknown reason, capturing output interferes with
49+
# the file descriptions opened by the asyncio IOLoop.
50+
# This leads to a nasty, flaky race condition that we haven't
51+
# been able to solve.
52+
pytest -vv -s
4853
- name: Install the Python dependencies for the examples
4954
run: |
5055
cd examples/simple && pip install -e .

jupyter_server/serverapp.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import warnings
3232
import webbrowser
3333
import urllib
34+
import inspect
3435

3536
from base64 import encodebytes
3637
try:
@@ -106,6 +107,7 @@
106107
from jupyter_server.extension.serverextension import ServerExtensionApp
107108
from jupyter_server.extension.manager import ExtensionManager
108109
from jupyter_server.extension.config import ExtensionConfigManager
110+
from jupyter_server.traittypes import TypeFromClasses
109111

110112
#-----------------------------------------------------------------------------
111113
# Module globals
@@ -1134,13 +1136,43 @@ def template_file_path(self):
11341136
help="""If True, display controls to shut down the Jupyter server, such as menu items or buttons."""
11351137
)
11361138

1137-
contents_manager_class = Type(
1139+
# REMOVE in VERSION 2.0
1140+
# Temporarily allow content managers to inherit from the 'notebook'
1141+
# package. We will deprecate this in the next major release.
1142+
contents_manager_class = TypeFromClasses(
11381143
default_value=LargeFileManager,
1139-
klass=ContentsManager,
1144+
klasses=[
1145+
'jupyter_server.services.contents.manager.ContentsManager',
1146+
'notebook.services.contents.manager.ContentsManager'
1147+
],
11401148
config=True,
11411149
help=_('The content manager class to use.')
11421150
)
11431151

1152+
# Throws a deprecation warning to notebook based contents managers.
1153+
@observe('contents_manager_class')
1154+
def _observe_contents_manager_class(self, change):
1155+
new = change['new']
1156+
# If 'new' is a class, get a string representing the import
1157+
# module path.
1158+
if inspect.isclass(new):
1159+
new = new.__module__
1160+
1161+
if new.startswith('notebook'):
1162+
self.log.warning(
1163+
"The specified 'contents_manager_class' class inherits a manager from the "
1164+
"'notebook' package. This is not guaranteed to work in future "
1165+
"releases of Jupyter Server. Instead, consider switching the "
1166+
"manager to inherit from the 'jupyter_server' managers. "
1167+
"Jupyter Server will temporarily allow 'notebook' managers "
1168+
"until its next major release (2.x)."
1169+
)
1170+
1171+
@observe('notebook_dir')
1172+
def _update_notebook_dir(self, change):
1173+
self.log.warning(_("notebook_dir is deprecated, use root_dir"))
1174+
self.root_dir = change['new']
1175+
11441176
kernel_manager_class = Type(
11451177
default_value=MappingKernelManager,
11461178
config=True,

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@
1818
from traitlets import Instance
1919

2020
from jupyter_server.utils import ensure_async
21+
from jupyter_server.traittypes import InstanceFromClasses
2122

2223

2324
class SessionManager(LoggingConfigurable):
2425

2526
kernel_manager = Instance('jupyter_server.services.kernels.kernelmanager.MappingKernelManager')
26-
contents_manager = Instance('jupyter_server.services.contents.manager.ContentsManager')
27+
contents_manager = InstanceFromClasses(
28+
[
29+
'jupyter_server.services.contents.manager.ContentsManager',
30+
'notebook.services.contents.manager.ContentsManager'
31+
]
32+
)
2733

2834
# Session database initialized below
2935
_cursor = None

0 commit comments

Comments
 (0)