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,