-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from davidbrochart/asphalt
Drop FPS in favor of Asphalt
- Loading branch information
Showing
109 changed files
with
3,590 additions
and
2,769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
component: | ||
type: jupyverse | ||
components: | ||
app: | ||
type: app | ||
auth: | ||
type: auth | ||
#auth: | ||
# type: auth_fief | ||
#auth: | ||
# type: noauth | ||
contents: | ||
type: contents | ||
frontend: | ||
type: frontend | ||
lab: | ||
type: lab | ||
jupyterlab: | ||
type: jupyterlab | ||
kernels: | ||
type: kernels | ||
login: | ||
type: login | ||
nbconvert: | ||
type: nbconvert | ||
resource_usage: | ||
type: resource_usage | ||
track_cpu_percent: true | ||
#retrolab: | ||
# type: retrolab | ||
terminals: | ||
type: terminals | ||
yjs: | ||
type: yjs | ||
|
||
logging: | ||
version: 1 | ||
disable_existing_loggers: false | ||
formatters: | ||
default: | ||
format: '[%(asctime)s %(levelname)s] %(message)s' | ||
handlers: | ||
console: | ||
class: logging.StreamHandler | ||
formatter: default | ||
root: | ||
handlers: [console] | ||
level: INFO | ||
loggers: | ||
webnotifier: | ||
level: DEBUG |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Jupyverse API | ||
|
||
The public API for Jupyverse. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Dict | ||
|
||
from pydantic import BaseModel, Extra | ||
|
||
from .app import App | ||
|
||
|
||
__version__ = "0.0.50" | ||
|
||
|
||
class Singleton(type): | ||
_instances: Dict = {} | ||
|
||
def __call__(cls, *args, **kwargs): | ||
if cls not in cls._instances: | ||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | ||
return cls._instances[cls] | ||
|
||
|
||
class Config(BaseModel): | ||
class Config: | ||
extra = Extra.forbid | ||
|
||
|
||
class Router: | ||
_app: App | ||
|
||
def __init__( | ||
self, | ||
app: App, | ||
) -> None: | ||
self._app = app | ||
|
||
@property | ||
def _type(self): | ||
return self.__class__.__name__ | ||
|
||
def include_router(self, router, **kwargs): | ||
self._app._include_router(router, self._type, **kwargs) | ||
|
||
def mount(self, path: str, *args, **kwargs) -> None: | ||
self._app._mount(path, self._type, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
from collections import defaultdict | ||
from typing import Dict, List | ||
|
||
from fastapi import FastAPI | ||
|
||
from ..exceptions import RedirectException, _redirect_exception_handler | ||
|
||
|
||
logger = logging.getLogger("app") | ||
|
||
|
||
class App: | ||
"""A wrapper around FastAPI that checks for endpoint path conflicts.""" | ||
|
||
_app: FastAPI | ||
_router_paths: Dict[str, List[str]] | ||
|
||
def __init__(self, app: FastAPI): | ||
self._app = app | ||
app.add_exception_handler(RedirectException, _redirect_exception_handler) | ||
self._router_paths = defaultdict(list) | ||
|
||
@property | ||
def _paths(self): | ||
return [path for router, paths in self._router_paths.items() for path in paths] | ||
|
||
def _include_router(self, router, _type, **kwargs) -> None: | ||
new_paths = [] | ||
for route in router.routes: | ||
path = kwargs.get("prefix", "") + route.path | ||
for _router, _paths in self._router_paths.items(): | ||
if path in _paths: | ||
raise RuntimeError( | ||
f"{_type} adds a handler for a path that is already defined in " | ||
f"{_router}: {path}" | ||
) | ||
logger.debug("%s added handler for path: %s", _type, path) | ||
new_paths.append(path) | ||
self._router_paths[_type].extend(new_paths) | ||
self._app.include_router(router, **kwargs) | ||
|
||
def _mount(self, path: str, _type, *args, **kwargs) -> None: | ||
for _router, _paths in self._router_paths.items(): | ||
if path in _paths: | ||
raise RuntimeError( | ||
f"{_type } mounts a path that is already defined in {_router}: {path}" | ||
) | ||
self._router_paths[_type].append(path) | ||
logger.debug("%s mounted path: %s", _type, path) | ||
self._app.mount(path, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Callable, Dict, List, Optional, Tuple | ||
|
||
from jupyverse_api import Config | ||
|
||
from .models import User # noqa | ||
|
||
|
||
class Auth(ABC): | ||
@abstractmethod | ||
def current_user(self, permissions: Optional[Dict[str, List[str]]] = None) -> Callable: | ||
... | ||
|
||
@abstractmethod | ||
async def update_user(self) -> Callable: | ||
... | ||
|
||
@abstractmethod | ||
def websocket_auth( | ||
self, | ||
permissions: Optional[Dict[str, List[str]]] = None, | ||
) -> Callable[[], Tuple[Any, Dict[str, List[str]]]]: | ||
... | ||
|
||
|
||
class AuthConfig(Config): | ||
pass |
2 changes: 0 additions & 2 deletions
2
plugins/noauth/fps_noauth/models.py → jupyverse_api/jupyverse_api/auth/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import asyncio | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
from typing import Dict, Union | ||
|
||
from jupyverse_api import Router | ||
|
||
from .models import Content, SaveContent | ||
|
||
|
||
class FileIdManager(ABC): | ||
stop_watching_files: asyncio.Event | ||
stopped_watching_files: asyncio.Event | ||
|
||
@abstractmethod | ||
async def get_path(self, file_id: str) -> str: | ||
... | ||
|
||
@abstractmethod | ||
async def get_id(self, file_path: str) -> str: | ||
... | ||
|
||
|
||
class Contents(Router, ABC): | ||
@property | ||
@abstractmethod | ||
def file_id_manager(self) -> FileIdManager: | ||
... | ||
|
||
@abstractmethod | ||
async def read_content( | ||
self, path: Union[str, Path], get_content: bool, as_json: bool = False | ||
) -> Content: | ||
... | ||
|
||
@abstractmethod | ||
async def write_content(self, content: Union[SaveContent, Dict]) -> None: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Dict, List, Optional, Union | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Content(BaseModel): | ||
name: str | ||
path: str | ||
last_modified: Optional[str] | ||
created: Optional[str] | ||
content: Optional[Union[str, Dict, List[Dict]]] | ||
format: Optional[str] | ||
mimetype: Optional[str] | ||
size: Optional[int] | ||
writable: bool | ||
type: str | ||
|
||
|
||
class SaveContent(BaseModel): | ||
content: Optional[Union[str, Dict]] | ||
format: str | ||
path: str | ||
type: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from fastapi import Request, Response | ||
from fastapi.responses import RedirectResponse | ||
|
||
|
||
class RedirectException(Exception): | ||
def __init__(self, redirect_to: str): | ||
self.redirect_to = redirect_to | ||
|
||
|
||
async def _redirect_exception_handler(request: Request, exc: RedirectException) -> Response: | ||
return RedirectResponse(url=exc.redirect_to) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from jupyverse_api import Config | ||
|
||
|
||
class FrontendConfig(Config): | ||
base_url: str = "/" | ||
collaborative: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from jupyverse_api import Config, Router | ||
|
||
|
||
class JupyterLab(Router): | ||
pass | ||
|
||
|
||
class JupyterLabConfig(Config): | ||
dev_mode: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from jupyverse_api import Router, Config | ||
|
||
|
||
class Kernels(Router, ABC): | ||
@abstractmethod | ||
async def watch_connection_files(self, path: Path) -> None: | ||
... | ||
|
||
|
||
class KernelsConfig(Config): | ||
default_kernel: str = "python3" | ||
connection_path: Optional[str] = None |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
from typing import Any, Dict, List, Tuple | ||
|
||
from fastapi import APIRouter | ||
from jupyverse_api import Router | ||
|
||
|
||
class Lab(Router, ABC): | ||
@abstractmethod | ||
def init_router( | ||
self, router: APIRouter, redirect_after_root: str | ||
) -> Tuple[Path, List[Dict[str, Any]]]: | ||
... | ||
|
||
@abstractmethod | ||
def get_federated_extensions(self, extensions_dir: Path) -> Tuple[List, List]: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from jupyverse_api import Router | ||
|
||
|
||
class Login(Router): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from asphalt.core import Component, Context | ||
from asphalt.web.fastapi import FastAPIComponent | ||
from fastapi import FastAPI | ||
|
||
from ..app import App | ||
|
||
|
||
class AppComponent(Component): | ||
async def start( | ||
self, | ||
ctx: Context, | ||
) -> None: | ||
app = await ctx.request_resource(FastAPI) | ||
|
||
_app = App(app) | ||
ctx.add_resource(_app) | ||
|
||
|
||
class JupyverseComponent(FastAPIComponent): | ||
async def start( | ||
self, | ||
ctx: Context, | ||
) -> None: | ||
await super().start(ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from jupyverse_api import Router | ||
|
||
|
||
class Nbconvert(Router): | ||
pass |
Empty file.
Oops, something went wrong.