Skip to content

Commit

Permalink
The server extension derives Jupytext's CM from the app CM
Browse files Browse the repository at this point in the history
Unless it already has Jupytext's attributes
#270
  • Loading branch information
mwouts committed Jul 6, 2019
1 parent fcb40c5 commit 904cc34
Show file tree
Hide file tree
Showing 2 changed files with 382 additions and 367 deletions.
13 changes: 9 additions & 4 deletions jupytext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from .reraise import reraise
from .version import __version__

try:
from .contentsmanager import build_jupytext_contents_manager_class
except ImportError as err:
build_jupytext_contents_manager = reraise(err)

try:
from .contentsmanager import TextFileContentsManager
except ImportError as err:
Expand All @@ -13,7 +18,7 @@

def load_jupyter_server_extension(app): # pragma: no cover
"""Use Jupytext's contents manager"""
if issubclass(app.contents_manager_class, TextFileContentsManager):
if hasattr(app.contents_manager_class, 'default_jupytext_formats'):
app.log.info("[Jupytext Server Extension] NotebookApp.contents_manager_class is "
"(a subclass of) jupytext.TextFileContentsManager already - OK")
return
Expand All @@ -22,9 +27,9 @@ def load_jupyter_server_extension(app): # pragma: no cover
# The contents manager was set at NotebookApp.init_configurables

# Let's change the contents manager class
app.log.info('[Jupytext Server Extension] Changing NotebookApp.contents_manager_class '
'from {} to jupytext.TextFileContentsManager'.format(app.contents_manager_class.__name__))
app.contents_manager_class = TextFileContentsManager
app.log.info('[Jupytext Server Extension] Deriving a JupytextContentsManager '
'from {}'.format(app.contents_manager_class.__name__))
app.contents_manager_class = build_jupytext_contents_manager_class(app.contents_manager_class)

try:
# And rerun selected init steps from https://github.com/jupyter/notebook/blob/
Expand Down
Loading

0 comments on commit 904cc34

Please sign in to comment.