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 2e5abcf commit 54000bb
Show file tree
Hide file tree
Showing 39 changed files with 500 additions and 471 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,15 +1,14 @@
from typing import Optional
from __future__ import annotations

from pydantic import BaseModel


class User(BaseModel):
anonymous: bool = True
username: str = ""
name: str = ""
display_name: str = ""
initials: Optional[str] = None
color: Optional[str] = None
avatar_url: Optional[str] = None
initials: str | None = None
color: str | None = None
avatar_url: str | None = None
workspace: str = "{}"
settings: str = "{}"
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")
...
17 changes: 9 additions & 8 deletions jupyverse_api/jupyverse_api/contents/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from typing import Dict, List, Optional, Union
from __future__ import annotations
from typing import Dict, List, 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]
last_modified: str | None
created: str | None
content: Union[str, Dict, List[Dict]] | None
format: str | None
mimetype: str | None
size: int | None
writable: bool
type: str


class SaveContent(BaseModel):
content: Optional[Union[str, Dict]]
content: Union[str, Dict] | None
format: str
path: str
type: str
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
6 changes: 3 additions & 3 deletions jupyverse_api/jupyverse_api/kernels/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Optional
from __future__ import annotations

from pydantic import BaseModel


class KernelInfo(BaseModel):
name: Optional[str] = None
id: Optional[str] = None
name: str | None = None
id: str | None = None


class CreateSession(BaseModel):
Expand Down
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 54000bb

Please sign in to comment.