From 60819d1208e15ca5bb5789b4f4899b8a8f4fda50 Mon Sep 17 00:00:00 2001 From: Daniel Juarez <34030545+djuarezg@users.noreply.github.com> Date: Thu, 4 May 2023 14:17:05 +0200 Subject: [PATCH] Allow to import from either jupyter_server or notebook packages Ref. https://github.com/danielfrg/s3contents/issues/161 --- s3contents/ipycompat.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/s3contents/ipycompat.py b/s3contents/ipycompat.py index 0b69b6d..3d73369 100644 --- a/s3contents/ipycompat.py +++ b/s3contents/ipycompat.py @@ -19,9 +19,23 @@ Checkpoints, GenericCheckpointsMixin, ) -from notebook.services.contents.filecheckpoints import GenericFileCheckpoints -from notebook.services.contents.filemanager import FileContentsManager -from notebook.services.contents.manager import ContentsManager + +# Ref. https://github.com/jupyter/nbdime/blob/c82362344e596efdc4f54c927d90338940e0fa41/nbdime/webapp/nb_server_extension.py#L16-L33 +# This allows solving conflicts between the class import from either notebook or jupyter_server +try: + from notebook.services.contents.filecheckpoints import GenericFileCheckpoints + from notebook.services.contents.filemanager import FileContentsManager + from notebook.services.contents.manager import ContentsManager +except ModuleNotFoundError: + pass + +try: + from jupyter_server.services.contents.filecheckpoints import GenericFileCheckpoints + from jupyter_server.services.contents.filemanager import FileContentsManager + from jupyter_server.services.contents.manager import ContentsManager +except ModuleNotFoundError: + pass + from notebook.utils import to_os_path from traitlets import ( Any,