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

Compatible with asynchronous contentsmanager #596

Merged
merged 2 commits into from
Jun 19, 2022
Merged
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
22 changes: 10 additions & 12 deletions nbdime/webapp/nb_server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from jinja2 import ChoiceLoader, FileSystemLoader

from jupyter_server.utils import url_path_join, to_os_path
from jupyter_server.utils import url_path_join, to_os_path, ensure_async

generic_checkpoint_mixin_types = []
file_checkpoint_mixin_types = []
Expand Down Expand Up @@ -156,43 +156,41 @@ def curdir(self):
class ExtensionApiDiffHandler(BaseGitDiffHandler):
"""Diff API handler that also handles diff to git HEAD"""

@gen.coroutine
def _get_checkpoint_notebooks(self, base):
async def _get_checkpoint_notebooks(self, base):
# Get the model for the current notebook:
cm = self.contents_manager
model = yield gen.maybe_future(cm.get(base, content=True, type='notebook'))
model = await ensure_async(cm.get(base, content=True, type='notebook'))
remote_nb = model['content']
# Get the model for the checkpoint notebook:
checkpoints = yield gen.maybe_future(cm.list_checkpoints(base))
checkpoints = await ensure_async(cm.list_checkpoints(base))
if not checkpoints:
# No checkpoints, indicate unchanged:
self.log.info('No checkpoints for file: %r, %r', base, checkpoints)
raise gen.Return((remote_nb, remote_nb))
return remote_nb, remote_nb
self.log.debug('Checkpoints: %r', checkpoints)
checkpoint = checkpoints[0]
if isinstance(cm.checkpoints, generic_checkpoint_mixin_types):
checkpoint_model = yield gen.maybe_future(
checkpoint_model = await ensure_async(
cm.checkpoints.get_notebook_checkpoint(checkpoint, base))
base_nb = checkpoint_model['content']
elif isinstance(cm.checkpoints, file_checkpoint_mixin_types):
path = yield gen.maybe_future(
path = await ensure_async(
cm.checkpoints.checkpoint_path(checkpoint['id'], base))
base_nb = read_notebook(path, on_null='minimal')
else:
raise RuntimeError('Unknown checkpoint handler interface')
raise gen.Return((base_nb, remote_nb))
return base_nb, remote_nb

@authenticated
@gen.coroutine
def post(self):
async def post(self):
# TODO: Add deprecation warning (for git/checkpoint only?)
# Assuming a request on the form "{'argname':arg}"
body = json.loads(escape.to_unicode(self.request.body))
base = body['base']
if base.startswith('git:'):
base_nb, remote_nb = self.get_git_notebooks(base[len('git:'):])
elif base.startswith('checkpoint:'):
base_nb, remote_nb = yield self._get_checkpoint_notebooks(base[len('checkpoint:'):])
base_nb, remote_nb = await self._get_checkpoint_notebooks(base[len('checkpoint:'):])
else:
# Regular files, call super
super(ExtensionApiDiffHandler, self).post()
Expand Down