Skip to content

Commit

Permalink
Make some jupyverse API classes ABC
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Mar 23, 2023
1 parent db957c3 commit 8b6fbfc
Show file tree
Hide file tree
Showing 36 changed files with 479 additions and 465 deletions.
2 changes: 2 additions & 0 deletions jupyverse_api/jupyverse_api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@


class App:
"""A wrapper around FastAPI that checks for endpoint path conflicts."""

_app: FastAPI
_router_paths: Dict[str, List[str]]

Expand Down
31 changes: 13 additions & 18 deletions jupyverse_api/jupyverse_api/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
from typing import Any, Callable, Dict, List, Optional, Tuple
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, List, Tuple

from jupyverse_api import Config
from pydantic import BaseModel

from .models import User # noqa

class User(BaseModel):
username: str = ""
name: str = ""
display_name: str = ""
initials: Optional[str] = None
color: Optional[str] = None
avatar_url: Optional[str] = None
workspace: str = "{}"
settings: str = "{}"

class Auth(ABC):
@abstractmethod
def current_user(self, permissions: Dict[str, List[str]] | None = None) -> Callable:
...

class Auth:
def current_user(self, permissions: Optional[Dict[str, List[str]]] = None) -> Callable:
raise RuntimeError("Not implemented")

@abstractmethod
async def update_user(self) -> Callable:
raise RuntimeError("Not implemented")
...

@abstractmethod
def websocket_auth(
self,
permissions: Optional[Dict[str, List[str]]] = None,
permissions: Dict[str, List[str]] | None = None,
) -> Callable[[], Tuple[Any, Dict[str, List[str]]]]:
raise RuntimeError("Not implemented")
...


class AuthConfig(Config):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Optional

from pydantic import BaseModel


class User(BaseModel):
anonymous: bool = True
username: str = ""
name: str = ""
display_name: str = ""
Expand Down
20 changes: 13 additions & 7 deletions jupyverse_api/jupyverse_api/contents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, Union

Expand All @@ -7,26 +8,31 @@
from .models import Content, SaveContent


class FileIdManager:
class FileIdManager(ABC):
stop_watching_files: asyncio.Event
stopped_watching_files: asyncio.Event

@abstractmethod
async def get_path(self, file_id: str) -> str:
raise RuntimeError("Not implemented")
...

@abstractmethod
async def get_id(self, file_path: str) -> str:
raise RuntimeError("Not implemented")
...


class Contents(Router):
class Contents(Router, ABC):
@property
@abstractmethod
def file_id_manager(self) -> FileIdManager:
raise RuntimeError("Not implemented")
...

@abstractmethod
async def read_content(
self, path: Union[str, Path], get_content: bool, as_json: bool = False
) -> Content:
raise RuntimeError("Not implemented")
...

@abstractmethod
async def write_content(self, content: Union[SaveContent, Dict]) -> None:
raise RuntimeError("Not implemented")
...
10 changes: 6 additions & 4 deletions jupyverse_api/jupyverse_api/kernels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from typing import Optional
from __future__ import annotations
from abc import ABC, abstractmethod
from pathlib import Path

from jupyverse_api import Router, Config


class Kernels(Router):
class Kernels(Router, ABC):
@abstractmethod
async def watch_connection_files(self, path: Path) -> None:
raise RuntimeError("Not implemented")
...


class KernelsConfig(Config):
default_kernel: str = "python3"
connection_path: Optional[str] = None
connection_path: str | None = None
9 changes: 6 additions & 3 deletions jupyverse_api/jupyverse_api/lab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +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):
class Lab(Router, ABC):
@abstractmethod
def init_router(
self, router: APIRouter, redirect_after_root: str
) -> Tuple[Path, List[Dict[str, Any]]]:
raise RuntimeError("Not implemented")
...

@abstractmethod
def get_federated_extensions(self, extensions_dir: Path) -> Tuple[List, List]:
raise RuntimeError("Not implemented")
...
Loading

0 comments on commit 8b6fbfc

Please sign in to comment.