Skip to content

Commit

Permalink
CLI enhancement + Bump versions (#23)
Browse files Browse the repository at this point in the history
* docs: jupyterlab

* fix: webpack

* chore: factor envs cli

* chore: use run_url

* chore: benchmarks

* chore: envs

* chore: utils

* fix: help

* fix: kernel type

* chore: use pathname

* chore: log info

* chore: datalayer run url

* fix: app

* fix: webpack

* bump version

* bump: version

* chore: benchmarks

* chore: bump version

* bump: version

* lint

* cli: add example

* chore: revert back to jupyterlab 4.0.9

* bump

* tune: webpack

* bump

* fix: build

* fix: build
  • Loading branch information
echarles authored Sep 1, 2024
1 parent 24af24f commit 15cf73f
Show file tree
Hide file tree
Showing 47 changed files with 543 additions and 242 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ publish-pypi: # publish the pypi package
@exec echo
@exec echo twine upload ./dist/*-py3-none-any.whl
@exec echo
@exec echo https://pypi.org/project/datalayer/#history
@exec echo https://pypi.org/project/datalayer-core/#history
6 changes: 3 additions & 3 deletions datalayer_core/authn/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
logger = logging.getLogger(__name__)


KERNELS_URL = "https://oss.datalayer.run"
DATALAYER_RUN_URL = "https://oss.datalayer.run"


if __name__ == "__main__":
from sys import argv

if len(argv) == 2:
ans = get_token(KERNELS_URL, port=int(argv[1]))
ans = get_token(DATALAYER_RUN_URL, port=int(argv[1]))
else:
ans = get_token(KERNELS_URL)
ans = get_token(DATALAYER_RUN_URL)

if ans is not None:
handle, token = ans
Expand Down
2 changes: 1 addition & 1 deletion datalayer_core/authn/apps/loginapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def start(self):
self.exit(1)

if self.token and self.user_handle:
self.log.info(f"🎉 Successfully authenticated as {self.user_handle} on {self.kernels_url}")
self.log.info(f"🎉 Successfully authenticated as {self.user_handle} on {self.run_url}")
print()
2 changes: 1 addition & 1 deletion datalayer_core/authn/apps/logoutapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def start(self):
"""
FIXME
self._fetch(
"{}/api/iam/v1/logout".format(self.kernels_url),
"{}/api/iam/v1/logout".format(self.run_url),
)
"""

Expand Down
21 changes: 21 additions & 0 deletions datalayer_core/authn/apps/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

from rich.console import Console
from rich.table import Table

def display_me(me: dict) -> None:
"""Display a my profile."""
table = Table(title="Profile")
table.add_column("ID", style="magenta", no_wrap=True)
table.add_column("Handle", style="cyan", no_wrap=True)
table.add_column("First name", style="green", no_wrap=True)
table.add_column("Last name", style="green", no_wrap=True)
table.add_row(
me["uid"],
me["handle_s"],
me["first_name_t"],
me["last_name_t"],
)
console = Console()
console.print(table)
6 changes: 3 additions & 3 deletions datalayer_core/authn/apps/whoamiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import warnings

from datalayer_core.cli.base import DatalayerCLIBaseApp
from ...kernels.utils import display_me
from datalayer_core.authn.apps.utils import display_me


class KernelWhoamiApp(DatalayerCLIBaseApp):
class WhoamiApp(DatalayerCLIBaseApp):
"""An application to list the kernels."""

description = """
Expand All @@ -24,7 +24,7 @@ def start(self):
self.exit(1)

response = self._fetch(
"{}/api/iam/v1/whoami".format(self.kernels_url),
"{}/api/iam/v1/whoami".format(self.run_url),
)
raw = response.json()
display_me(raw.get("profile", {}))
22 changes: 12 additions & 10 deletions datalayer_core/authn/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
HERE = Path(__file__).parent


USE_JUPYTER_SERVER: bool = False
# Do not set it to True, the Jupyter Server
# handlers are not yet implemented.
USE_JUPYTER_SERVER_FOR_LOGIN: bool = False


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -94,12 +96,12 @@ def do_GET(self):
parts = urllib.parse.urlsplit(self.path)
if parts[2].strip("/").endswith("oauth/callback"):
self._save_token(parts[3])
elif parts[2] in {"/", "/login/cli"}:
elif parts[2] in {"/", "/datalayer/login/cli"}:
content = LANDING_PAGE.format(
config=json.dumps(
{
"runUrl": self.server.kernels_url,
"iamRunUrl": self.server.kernels_url,
"runUrl": self.server.run_url,
"iamRunUrl": self.server.run_url,
"whiteLabel": False
}
)
Expand Down Expand Up @@ -145,10 +147,10 @@ def __init__(
self,
server_address: tuple[str | bytes | bytearray, int],
RequestHandlerClass: t.Callable[[t.Any, t.Any, t.Self], BaseRequestHandler],
kernels_url: str,
run_url: str,
bind_and_activate: bool = True,
) -> None:
self.kernels_url = kernels_url
self.run_url = run_url
self.user_handle = None
self.token = None
super().__init__(server_address, RequestHandlerClass, bind_and_activate)
Expand All @@ -166,27 +168,27 @@ def finish_request(self, request, client_address):


def get_token(
kernels_url: str, port: int | None = None, logger: logging.Logger = logger
run_url: str, port: int | None = None, logger: logging.Logger = logger
) -> tuple[str, str] | None:
"""Get the user handle and token."""

server_address = ("", port or find_http_port())
port = server_address[1]

if USE_JUPYTER_SERVER == True:
if USE_JUPYTER_SERVER_FOR_LOGIN == True:
set_server_port(port)
logger.info(f"Waiting for user logging, open http://localhost:{port}. Press CTRL+C to abort.\n")
sys.argv = [
"",
"--JupyterKernelsExtensionApp.run_url", kernels_url,
"--DatalayerExtensionApp.run_url", run_url,
"--ServerApp.disable_check_xsrf", "True",
]
launch_new_instance()
logger.debug("Authentication finished.")
# return None if httpd.token is None else (httpd.user_handle, httpd.token)
return None
else:
httpd = DualStackServer(server_address, LoginRequestHandler, kernels_url)
httpd = DualStackServer(server_address, LoginRequestHandler, run_url)
logger.info(f"Waiting for user logging, open http://localhost:{port}. Press CTRL+C to abort.\n")
try:
httpd.serve_forever()
Expand Down
3 changes: 3 additions & 0 deletions datalayer_core/benchmarks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

29 changes: 29 additions & 0 deletions datalayer_core/benchmarks/benchmarksapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

from datalayer_core.application import NoStart

from datalayer_core.cli.base import DatalayerCLIBaseApp
from datalayer_core.benchmarks.web.webapp import BenchmarksWebApp

class BenchmarksApp(DatalayerCLIBaseApp):
"""An application to run benchmarks."""

description = """
An application to run benchmarks.
"""

_requires_auth = False

subcommands = {
"web": (BenchmarksWebApp, BenchmarksWebApp.description.splitlines()[0]),
}

def start(self):
try:
super().start()
self.log.info(f"One of `{'` `'.join(BenchmarksApp.subcommands.keys())}` must be specified.")
self.exit(1)
except NoStart:
pass
self.exit(0)
3 changes: 3 additions & 0 deletions datalayer_core/benchmarks/web/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

32 changes: 32 additions & 0 deletions datalayer_core/benchmarks/web/webapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

import sys

from datalayer_core.cli.base import DatalayerCLIBaseApp
from datalayer_core.serverapplication import launch_new_instance


class BenchmarksWebApp(DatalayerCLIBaseApp):
"""An application to show the benchmarks webapp."""

description = """
An application to show the benchmarks webapp.
"""

_requires_auth = False

def start(self):
"""Start the app."""
if len(self.extra_args) > 1: # pragma: no cover
self.log.warning("Too many arguments were provided for kernel create.")
self.print_help()
self.exit(1)
self.clear_instance()
sys.argv = [
'',
'--ServerApp.disable_check_xsrf=True',
'--DatalayerExtensionApp.benchmarks=True',
f'--DatalayerExtensionApp.run_url={self.run_url}',
]
launch_new_instance()
Loading

0 comments on commit 15cf73f

Please sign in to comment.