Skip to content

Commit

Permalink
Merge pull request #392 from afshin/contents-manager
Browse files Browse the repository at this point in the history
Enable notebook ContentsManager in jupyter_server
  • Loading branch information
Zsailer authored Jan 29, 2021
2 parents 2477da6 + 7978e46 commit 5dc20a3
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/python-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ jobs:
pip check
- name: Run the tests
run: |
pytest -vv
# Disable capturing (-s) output from Pytest on Windows.
# For an unknown reason, capturing output interferes with
# the file descriptions opened by the asyncio IOLoop.
# This leads to a nasty, flaky race condition that we haven't
# been able to solve.
pytest -vv -s
- name: Install the Python dependencies for the examples
run: |
cd examples/simple && pip install -e .
Expand Down
36 changes: 34 additions & 2 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import warnings
import webbrowser
import urllib
import inspect

from base64 import encodebytes
try:
Expand Down Expand Up @@ -106,6 +107,7 @@
from jupyter_server.extension.serverextension import ServerExtensionApp
from jupyter_server.extension.manager import ExtensionManager
from jupyter_server.extension.config import ExtensionConfigManager
from jupyter_server.traittypes import TypeFromClasses

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

contents_manager_class = Type(
# REMOVE in VERSION 2.0
# Temporarily allow content managers to inherit from the 'notebook'
# package. We will deprecate this in the next major release.
contents_manager_class = TypeFromClasses(
default_value=LargeFileManager,
klass=ContentsManager,
klasses=[
'jupyter_server.services.contents.manager.ContentsManager',
'notebook.services.contents.manager.ContentsManager'
],
config=True,
help=_('The content manager class to use.')
)

# Throws a deprecation warning to notebook based contents managers.
@observe('contents_manager_class')
def _observe_contents_manager_class(self, change):
new = change['new']
# If 'new' is a class, get a string representing the import
# module path.
if inspect.isclass(new):
new = new.__module__

if new.startswith('notebook'):
self.log.warning(
"The specified 'contents_manager_class' class inherits a manager from the "
"'notebook' package. This is not guaranteed to work in future "
"releases of Jupyter Server. Instead, consider switching the "
"manager to inherit from the 'jupyter_server' managers. "
"Jupyter Server will temporarily allow 'notebook' managers "
"until its next major release (2.x)."
)

@observe('notebook_dir')
def _update_notebook_dir(self, change):
self.log.warning(_("notebook_dir is deprecated, use root_dir"))
self.root_dir = change['new']

kernel_manager_class = Type(
default_value=MappingKernelManager,
config=True,
Expand Down
8 changes: 7 additions & 1 deletion jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
from traitlets import Instance

from jupyter_server.utils import ensure_async
from jupyter_server.traittypes import InstanceFromClasses


class SessionManager(LoggingConfigurable):

kernel_manager = Instance('jupyter_server.services.kernels.kernelmanager.MappingKernelManager')
contents_manager = Instance('jupyter_server.services.contents.manager.ContentsManager')
contents_manager = InstanceFromClasses(
[
'jupyter_server.services.contents.manager.ContentsManager',
'notebook.services.contents.manager.ContentsManager'
]
)

# Session database initialized below
_cursor = None
Expand Down
Loading

0 comments on commit 5dc20a3

Please sign in to comment.