Skip to content

Commit

Permalink
Add CLI and JupyterLab plugins for IAM and Kernels (#21)
Browse files Browse the repository at this point in the history
* chore: activate all plugins

* chore: add iam and kernels

* chore: working cli

* chore: cli app

* fix: exec

* chore: rename to datalayer_core

* chore: license

* chore: rm jupyterlab from deps

* chore: revert to datalayer

* chore: revert to datalayer extensions

* lint

* chore: set version
  • Loading branch information
echarles authored Aug 13, 2024
1 parent 80858fb commit 2ddcc32
Show file tree
Hide file tree
Showing 72 changed files with 3,455 additions and 162 deletions.
20 changes: 17 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ node_modules/
*.egg-info/
.ipynb_checkpoints
*.tsbuildinfo
datalayer/labextension
datalayer_core/labextension
# Version file is handled by hatchling
datalayer/_version.py

datalayer/static/*.js
datalayer/static/*.css
datalayer_core/static/*.js
datalayer_core/static/*.css

coverage

Expand Down Expand Up @@ -126,3 +126,17 @@ dmypy.json
.DS_Store

*ystore.db


# Include
!**/.*ignore
!**/.*rc
!**/.*rc.js
!**/.*rc.json
!**/.*rc.yml
!**/.*rc.yaml
!**/.*config
!*.*rc.json
!**/.env
!.github
!.devcontainer
48 changes: 48 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
header:
license:
spdx-id: Datalayer
copyright-owner: Datalayer, Inc.
copyright-year: 2023-2024
content: |
Copyright (c) [year] [owner]
Distributed under the terms of the Modified BSD License.
paths-ignore:
- '**/*.apt'
- '**/*.cedar'
- '**/*.dash'
- '**/*.fga'
- '**/*.ipynb'
- '**/*.j2'
- '**/*.json'
- '**/*.mamba'
- '**/*.md'
- '**/*.mod'
- '**/*.nblink'
- '**/*.rego'
- '**/*.sum'
- '**/*.svg'
- '**/*.template'
- '**/*.tsbuildinfo'
- '**/*.txt'
- '**/*.yaml'
- '**/*.yml'
- '**/*_key'
- '**/*_key.pub'
- '**/.*'
- '**/LICENSE.txt'
- '**/MANIFEST.in'
- '**/build'
- '**/lib'
- '**/node_modules'
- '**/schemas'
- '**/ssh/*'
- '**/static'
- '**/themes'
- '**/typings'
- '**/*.patch'
- '**/*.bundle.js'
- '**/*.map.js'
- 'LICENSE'

comment: on-failure
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)

# Ξ Datalayer
# Ξ Datalayer Core

> Datalayer core.
Datalayer is the base foundation package used by many other Datalayer packages. It contains base application classes and configuration inherited by other projects.
Datalayer Core is the base foundation package used by many other Datalayer packages. It contains base application classes and configuration inherited by other projects.

It is also the meta package to get the other Datalayer packages installed.

Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

@pytest.fixture
def jp_server_config(jp_server_config):
return {"ServerApp": {"jpserver_extensions": {"datalayer": True}}}
return {"ServerApp": {"jpserver_extensions": {"datalayer_core": True}}}
1 change: 0 additions & 1 deletion datalayer/static/README.md

This file was deleted.

1 change: 0 additions & 1 deletion datalayer/tests/__init__.py

This file was deleted.

8 changes: 4 additions & 4 deletions datalayer/__init__.py → datalayer_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List

from ._version import __version__
from .serverapplication import DatalayerExtensionApp
from datalayer_core._version import __version__
from datalayer_core.serverapplication import DatalayerExtensionApp

try:
from .lab import DatalayerLabApp
Expand All @@ -12,11 +12,11 @@

def _jupyter_server_extension_points() -> List[Dict[str, Any]]:
return [{
"module": "datalayer",
"module": "datalayer_core",
"app": DatalayerExtensionApp,
},
{
"module": "datalayer",
"module": "datalayer_core",
"app": DatalayerLabApp,
}]

Expand Down
2 changes: 1 addition & 1 deletion datalayer/__main__.py → datalayer_core/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The main for Datalayer."""

from datalayer.serverapplication import main
from datalayer_core.serverapplication import main

if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions datalayer_core/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is auto-generated by Hatchling. As such, do not:
# - modify
# - track in version control e.g. be sure to add to .gitignore
__version__ = VERSION = '1.1.2'
6 changes: 6 additions & 0 deletions datalayer_core/about/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## About

Datalayer provides a command line tool allowing to list, create, terminate and open a console against
a remote kernel.

Read more on https://docs.datalayer.run
36 changes: 36 additions & 0 deletions datalayer_core/about/aboutapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

from pathlib import Path

from datalayer_core.application import NoStart
from rich.console import Console
from rich.markdown import Markdown

from datalayer_core.cli.base import DatalayerCLIBaseApp


HERE = Path(__file__).parent


class DatalayerAboutApp(DatalayerCLIBaseApp):
"""Kernel About application."""

description = """
An application to print useful information
about jupyter kernels.
"""

_requires_auth = False


def start(self):
try:
super().start()
console = Console()
with open(HERE / "about.md") as readme:
markdown = Markdown(readme.read())
console.print(markdown)
except NoStart:
pass
self.exit(0)
2 changes: 1 addition & 1 deletion datalayer/application.py → datalayer_core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NoStart(Exception): # noqa
class DatalayerApp(Application):
"""Base class for Datalayer applications"""

name = "datalayer" # override in subclasses
name = "datalayer_core" # override in subclasses
description = "A Datalayer Application"

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

from __future__ import annotations

import logging

from datalayer_core.authn.http_server import get_token


logging.basicConfig(level=logging.INFO)

logger = logging.getLogger(__name__)


KERNELS_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]))
else:
ans = get_token(KERNELS_URL)

if ans is not None:
handle, token = ans
else:
handle = None
token = None

logger.info(f"Logged as {handle} with token: {token}")
Empty file.
27 changes: 27 additions & 0 deletions datalayer_core/authn/apps/loginapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

import warnings

from datalayer_core.cli.base import DatalayerCLIBaseApp


class DatalayerLoginApp(DatalayerCLIBaseApp):
"""An application to log into a remote kernel provider."""

description = """
An application to log into a remote kernel provider.
jupyter kernels login
"""

def start(self):
"""Start the app."""
if len(self.extra_args) > 0: # pragma: no cover
warnings.warn("Too many arguments were provided for login.")
self.print_help()
self.exit(1)

if self.token and self.user_handle:
self.log.info(f"🎉 Successfully authenticated as {self.user_handle} on {self.kernels_url}")
print()
34 changes: 34 additions & 0 deletions datalayer_core/authn/apps/logoutapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) Datalayer Development Team.
# Distributed under the terms of the Modified BSD License.

import warnings

from datalayer_core.cli.base import DatalayerCLIBaseApp


class DatalayerLogoutApp(DatalayerCLIBaseApp):
"""An application to logout of a remote kernel provider."""

description = """
An application to logout of a remote kernel provider.
jupyter kernels logout
"""

_requires_auth = False


def start(self):
"""Start the app."""
if len(self.extra_args) > 0: # pragma: no cover
warnings.warn("Too many arguments were provided for logout.")
self.print_help()
self.exit(1)
"""
FIXME
self._fetch(
"{}/api/iam/v1/logout".format(self.kernels_url),
)
"""

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

import warnings

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


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

description = """
An application to list the kernels.
jupyter kernels list
"""

def start(self):
"""Start the app."""
if len(self.extra_args) > 0: # pragma: no cover
warnings.warn("Too many arguments were provided for kernel list.")
self.print_help()
self.exit(1)

response = self._fetch(
"{}/api/iam/v1/whoami".format(self.kernels_url),
)
raw = response.json()
display_me(raw.get("profile", {}))
Loading

0 comments on commit 2ddcc32

Please sign in to comment.