diff --git a/package.json b/package.json index ed195bb..867ae81 100644 --- a/package.json +++ b/package.json @@ -80,16 +80,6 @@ "access": "public" }, "jupyterlab": { - "discovery": { - "server": { - "managers": [ - "pip" - ], - "base": { - "name": "tiledb-prompt-options" - } - } - }, "extension": true, "outputDir": "tiledb-prompt-options/labextension" } diff --git a/setup.py b/setup.py index ea786e0..b56f1f5 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ """ tiledb-prompt-options setup """ + import json import sys from pathlib import Path diff --git a/tiledb-prompt-options/__init__.py b/tiledb-prompt-options/__init__.py index 8826514..360f7cc 100644 --- a/tiledb-prompt-options/__init__.py +++ b/tiledb-prompt-options/__init__.py @@ -11,26 +11,3 @@ def _jupyter_labextension_paths(): return [{"src": "labextension", "dest": data["name"]}] - - -from .handlers import setup_handlers - - -def _jupyter_server_extension_points(): - return [{"module": "tiledb-prompt-options"}] - - -def _load_jupyter_server_extension(server_app): - """Registers the API handler to receive HTTP requests from the frontend extension. - - Parameters - ---------- - server_app: jupyterlab.labapp.LabApp - JupyterLab application instance - """ - setup_handlers(server_app.web_app) - server_app.log.info("Registered tiledb-prompt-options extension") - - -# For backward compatibility with notebook server - useful for Binder/JupyterHub -load_jupyter_server_extension = _load_jupyter_server_extension diff --git a/tiledb-prompt-options/extension.py b/tiledb-prompt-options/extension.py deleted file mode 100644 index aaaad77..0000000 --- a/tiledb-prompt-options/extension.py +++ /dev/null @@ -1,73 +0,0 @@ -from tornado import gen, web -from jupyter_server.services.contents.handlers import ContentsHandler, validate_model -from notebook.utils import maybe_future - - -class TileDBHandler(ContentsHandler): - @web.authenticated - @gen.coroutine - def post(self, path=""): - """Create a new file in the specified path. - POST creates new files. The server always decides on the name. - POST /api/contents/path - New untitled, empty file or directory. - POST /api/contents/path - with body {"copy_from" : "/path/to/OtherNotebook.ipynb"} - New copy of OtherNotebook in path - - This post function is able to pass the TileDB options to the - new_untitled() function in TileDBContentsManager. - """ - cm = self.contents_manager - file_exists = yield maybe_future(cm.file_exists(path)) - if file_exists: - raise web.HTTPError(400, "Cannot POST to files, use PUT instead.") - - dir_exists = yield maybe_future(cm.dir_exists(path)) - if not dir_exists: - raise web.HTTPError(404, "No such directory: %s" % path) - - model = self.get_json_body() - - if model is not None: - copy_from = model.get("copy_from") - nbpath = model.get("path", "") - ext = model.get("ext", "") - type = model.get("type", "") - options = model.get("options", "") - if copy_from: - yield self._copy(copy_from, nbpath) - else: - yield self._new_untitled(nbpath, type=type, ext=ext, options=options) - else: - yield self._new_untitled(path) - - @web.authenticated - @gen.coroutine - def get(self, path=""): - uri = self.request.uri - base_uri = uri.split("?")[0] - parts = base_uri.split("/") - final_path = "/" + "/".join(parts[-3:]) - model = yield maybe_future(self.contents_manager.get(final_path)) - - self.set_status(200) - self._finish_model(model) - - @gen.coroutine - def _new_untitled(self, path, type="", ext="", options=""): - """Create a new, empty untitled entity. - - This function passes the TileDB options to the new_untitled() method.""" - self.log.info( - "Creating new %s in %s with options %s", type or "file", path, options - ) - - model = yield maybe_future( - self.contents_manager.new_untitled( - path=path, type=type, ext=ext, options=options - ) - ) - self.set_status(201) - validate_model(model, expect_content=False) - self._finish_model(model) diff --git a/tiledb-prompt-options/handlers.py b/tiledb-prompt-options/handlers.py deleted file mode 100644 index c6501ab..0000000 --- a/tiledb-prompt-options/handlers.py +++ /dev/null @@ -1,44 +0,0 @@ -import json -import os - -from jupyter_server.base.handlers import APIHandler -from jupyter_server.utils import url_path_join -import tornado - -import tiledb.cloud - -from .extension import TileDBHandler # noqa: F401 - - -class RouteHandler(APIHandler): - # The following decorator should be present on all verb methods (head, get, post, - # patch, put, delete, options) to ensure only authorized user can request the - # Jupyter server - @tornado.web.authenticated - def get(self): - TOKEN = os.getenv("TILEDB_REST_TOKEN") - API_HOST = os.getenv("TILEDB_REST_HOST") - self.finish(json.dumps({"token": TOKEN, "api_host": API_HOST})) - - -def setup_handlers(web_app): - host_pattern = ".*$" - - # Register handlers for all cloud endpoints (for user and user's organizations) - profile = tiledb.cloud.client.user_profile() - tiledb_cloud_base = "/api/contents/cloud/owned/{}" - route_patterns = [] - route_patterns.append(tiledb_cloud_base.format(profile.username)) - - for organization in profile.organizations: - route_patterns.append(tiledb_cloud_base.format(organization.organization_name)) - - for url in route_patterns: - rp = url_path_join(web_app.settings["base_url"], url) - web_app.add_handlers(host_pattern, [(rp, TileDBHandler)]) - - # Register handler for /get_access_token endpoint - base_url = web_app.settings["base_url"] - route_pattern = url_path_join(base_url, "get_access_token") - handlers = [(route_pattern, RouteHandler)] - web_app.add_handlers(host_pattern, handlers)