Skip to content

Commit

Permalink
Use FastAIO v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Feb 3, 2025
1 parent 50df2f4 commit 2979400
Show file tree
Hide file tree
Showing 54 changed files with 186 additions and 210 deletions.
22 changes: 11 additions & 11 deletions jupyverse_api/jupyverse_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, List, Tuple

import rich_click as click
from fastaio import get_config, get_root_component, merge_config
from fastaio import get_config, get_root_module, merge_config
from fastaio import main as fastaio_main

if sys.version_info < (3, 10):
Expand Down Expand Up @@ -88,29 +88,29 @@ def main(
set_list.append(f"allow_origins={allow_origins_str}")
set_list.append(f"query_params={query_params_str}")
fastaio_main.callback(
"jupyverse_api.main:JupyverseComponent",
"jupyverse_api.main:JupyverseModule",
set_=set_list,
) # type: ignore
cli_config = get_config()
pluggin_config = get_pluggin_config(disable)
config = merge_config(cli_config, pluggin_config)
root_component = get_root_component(config)
root_component.run()
root_module = get_root_module(config)
root_module.run()


def get_pluggin_config(disable: Tuple[str, ...]) -> dict[str, Any]:
jupyverse_components = [
jupyverse_modules = [
ep.name
for ep in entry_points(group="jupyverse.components")
for ep in entry_points(group="jupyverse.modules")
if ep.name not in disable
]
config = {
"root_component": {
"components": {
component: {
"type": component
"root_module": {
"modules": {
module: {
"type": module
}
for component in jupyverse_components
for module in jupyverse_modules
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions jupyverse_api/jupyverse_api/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import structlog
from anyio import Event, create_task_group
from fastaio import Component
from fastaio.web.fastapi import FastAPIComponent
from fastaio import Module
from fastaio.web.fastapi import FastAPIModule
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel, Json
Expand All @@ -19,7 +19,7 @@
logger = structlog.get_logger()


class AppComponent(Component):
class AppModule(Module):
def __init__(
self,
name: str,
Expand All @@ -30,13 +30,12 @@ def __init__(
self.mount_path = mount_path

async def prepare(self) -> None:
app = await self.get_resource(FastAPI)
app = await self.get(FastAPI)
_app = App(app, mount_path=self.mount_path)
self.add_resource(_app)
self.done()
self.put(_app)


class JupyverseComponent(FastAPIComponent):
class JupyverseModule(FastAPIModule):
def __init__(self, name: str, **kwargs) -> None:
self.jupyverse_config = JupyverseConfig(**kwargs)
if self.jupyverse_config.debug:
Expand All @@ -51,7 +50,7 @@ def __init__(self, name: str, **kwargs) -> None:

async def prepare(self) -> None:
await super().prepare()
app = await self.get_resource(App)
app = await self.get(App)
if self.jupyverse_config.allow_origins:
app.add_middleware(
CORSMiddleware,
Expand All @@ -66,9 +65,9 @@ async def prepare(self) -> None:
self._host = f"http://{self._host}"
self._port = self.jupyverse_config.port
host_url = Host(url=f"{self._host}:{self._port}/")
self.add_resource(self._query_params)
self.add_resource(host_url)
self.add_resource(self.lifespan)
self.put(self._query_params)
self.put(host_url)
self.put(self.lifespan)

async def start(self) -> None:
async with create_task_group() as tg:
Expand Down
12 changes: 6 additions & 6 deletions jupyverse_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"pydantic >=2,<3",
"fastapi >=0.95.0,<1",
"rich-click >=1.6.1,<2",
"fastaio[web] >=0.3.0,<0.4.0",
"fastaio[web] >=0.4.0,<0.5.0",
]
dynamic = ["version"]

Expand All @@ -42,12 +42,12 @@ Source = "https://github.com/jupyter-server/jupyverse/jupyverse_api"
[project.scripts]
jupyverse = "jupyverse_api.cli:main"

[project.entry-points."fastaio.components"]
app = "jupyverse_api.main:AppComponent"
jupyverse = "jupyverse_api.main:JupyverseComponent"
[project.entry-points."fastaio.modules"]
app = "jupyverse_api.main:AppModule"
jupyverse = "jupyverse_api.main:JupyverseModule"

[project.entry-points."jupyverse.components"]
app = "jupyverse_api.main:AppComponent"
[project.entry-points."jupyverse.modules"]
app = "jupyverse_api.main:AppModule"

[tool.hatch.version]
path = "jupyverse_api/__init__.py"
1 change: 0 additions & 1 deletion plugins/auth/MANIFEST.in

This file was deleted.

14 changes: 7 additions & 7 deletions plugins/auth/fps_auth/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import structlog
from fastaio import Component
from fastaio import Module
from fastapi_users.exceptions import UserAlreadyExists

from jupyverse_api.app import App
Expand All @@ -13,19 +13,19 @@
log = structlog.get_logger()


class AuthComponent(Component):
class AuthModule(Module):
def __init__(self, name: str, **kwargs):
super().__init__(name)
self.auth_config = _AuthConfig(**kwargs)

async def prepare(self) -> None:
self.add_resource(self.auth_config, types=AuthConfig)
self.put(self.auth_config, types=AuthConfig)

app = await self.get_resource(App)
frontend_config = await self.get_resource(FrontendConfig)
app = await self.get(App)
frontend_config = await self.get(FrontendConfig)

auth = auth_factory(app, self.auth_config, frontend_config)
self.add_resource(auth, types=Auth)
self.put(auth, types=Auth)

await auth.db.create_db_and_tables()

Expand Down Expand Up @@ -56,5 +56,5 @@ async def prepare(self) -> None:
)

if self.auth_config.mode == "token":
query_params = await self.get_resource(QueryParams)
query_params = await self.get(QueryParams)
query_params.d["token"] = self.auth_config.token
4 changes: 2 additions & 2 deletions plugins/auth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ ignore = [ ".*",]
skip = [ "check-links",]

[project.entry-points]
"fastaio.components" = {auth = "fps_auth.main:AuthComponent"}
"jupyverse.components" = {auth = "fps_auth.main:AuthComponent"}
"fastaio.modules" = {auth = "fps_auth.main:AuthModule"}
"jupyverse.modules" = {auth = "fps_auth.main:AuthModule"}

[tool.hatch.version]
path = "fps_auth/__init__.py"
1 change: 0 additions & 1 deletion plugins/auth_fief/MANIFEST.in

This file was deleted.

12 changes: 6 additions & 6 deletions plugins/auth_fief/fps_auth_fief/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastaio import Component
from fastaio import Module

from jupyverse_api.app import App
from jupyverse_api.auth import Auth, AuthConfig
Expand All @@ -7,14 +7,14 @@
from .routes import auth_factory


class AuthFiefComponent(Component):
class AuthFiefModule(Module):
def __init__(self, name: str, **kwargs):
self.auth_fief_config = _AuthFiefConfig(**kwargs)

async def start(self) -> None:
self.add_resource(self.auth_fief_config, types=AuthConfig)
async def prepare(self) -> None:
self.put(self.auth_fief_config, types=AuthConfig)

app = await self.request_resource(App)
app = await self.get(App)

auth_fief = auth_factory(app, self.auth_fief_config)
self.add_resource(auth_fief, types=Auth)
self.put(auth_fief, types=Auth)
10 changes: 5 additions & 5 deletions plugins/auth_jupyterhub/fps_auth_jupyterhub/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastaio import Component
from fastaio import Module
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

from jupyverse_api.app import App
Expand All @@ -9,19 +9,19 @@
from .routes import auth_factory


class AuthJupyterHubComponent(Component):
class AuthJupyterHubModule(Module):
def __init__(self, name: str, **kwargs):
super().__init__(name)
self.auth_jupyterhub_config = AuthJupyterHubConfig(**kwargs)

async def prepare(self) -> None:
self.add_resource(self.auth_jupyterhub_config, types=AuthConfig)
app = await self.get_resource(App)
self.put(self.auth_jupyterhub_config, types=AuthConfig)
app = await self.get(App)
self.db_engine = create_async_engine(self.auth_jupyterhub_config.db_url)
self.db_session = AsyncSession(self.db_engine)

auth_jupyterhub = auth_factory(app, self.db_session)
self.add_resource(auth_jupyterhub, types=Auth)
self.put(auth_jupyterhub, types=Auth)

async with self.db_engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
Expand Down
2 changes: 1 addition & 1 deletion plugins/auth_jupyterhub/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ignore = [ ".*",]
skip = [ "check-links" ]

[project.entry-points]
"jupyverse.components" = {auth_jupyterhub = "fps_auth_jupyterhub.main:AuthJupyterHubComponent"}
"jupyverse.modules" = {auth_jupyterhub = "fps_auth_jupyterhub.main:AuthJupyterHubModule"}

[tool.hatch.version]
path = "fps_auth_jupyterhub/__init__.py"
1 change: 0 additions & 1 deletion plugins/contents/MANIFEST.in

This file was deleted.

10 changes: 5 additions & 5 deletions plugins/contents/fps_contents/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastaio import Component
from fastaio import Module

from jupyverse_api.app import App
from jupyverse_api.auth import Auth
Expand All @@ -7,10 +7,10 @@
from .routes import _Contents


class ContentsComponent(Component):
class ContentsModule(Module):
async def prepare(self) -> None:
app = await self.get_resource(App)
auth = await self.get_resource(Auth) # type: ignore
app = await self.get(App)
auth = await self.get(Auth) # type: ignore

contents = _Contents(app, auth)
self.add_resource(contents, types=Contents)
self.put(contents, types=Contents)
4 changes: 2 additions & 2 deletions plugins/contents/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ ignore = [ ".*",]
skip = [ "check-links",]

[project.entry-points]
"fastaio.components" = {contents = "fps_contents.main:ContentsComponent"}
"jupyverse.components" = {contents = "fps_contents.main:ContentsComponent"}
"fastaio.modules" = {contents = "fps_contents.main:ContentsModule"}
"jupyverse.modules" = {contents = "fps_contents.main:ContentsModule"}

[tool.hatch.version]
path = "fps_contents/__init__.py"
1 change: 0 additions & 1 deletion plugins/frontend/MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions plugins/frontend/fps_frontend/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from fastaio import Component
from fastaio import Module

from jupyverse_api.frontend import FrontendConfig


class FrontendComponent(Component):
class FrontendModule(Module):
def __init__(self, name: str, **kwargs):
super().__init__(name)
self.frontend_config = FrontendConfig(**kwargs)

async def prepare(self) -> None:
self.add_resource(self.frontend_config, types=FrontendConfig)
self.put(self.frontend_config, types=FrontendConfig)
4 changes: 2 additions & 2 deletions plugins/frontend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ignore = [".*"]
skip = ["check-links"]

[project.entry-points]
"fastaio.components" = {frontend = "fps_frontend.main:FrontendComponent"}
"jupyverse.components" = {frontend = "fps_frontend.main:FrontendComponent"}
"fastaio.modules" = {frontend = "fps_frontend.main:FrontendModule"}
"jupyverse.modules" = {frontend = "fps_frontend.main:FrontendModule"}

[tool.hatch.version]
path = "fps_frontend/__init__.py"
1 change: 0 additions & 1 deletion plugins/jupyterlab/MANIFEST.in

This file was deleted.

18 changes: 8 additions & 10 deletions plugins/jupyterlab/fps_jupyterlab/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastaio import Component
from fastaio import Module

from jupyverse_api.app import App
from jupyverse_api.auth import Auth
Expand All @@ -9,20 +9,18 @@
from .routes import _JupyterLab


class JupyterLabComponent(Component):
class JupyterLabModule(Module):
def __init__(self, name: str, **kwargs):
super().__init__(name)
self.jupyterlab_config = JupyterLabConfig(**kwargs)

async def prepare(self) -> None:
self.add_resource(self.jupyterlab_config, types=JupyterLabConfig)
self.put(self.jupyterlab_config, types=JupyterLabConfig)

app = await self.get_resource(App)
auth = await self.get_resource(Auth)
frontend_config = await self.get_resource(FrontendConfig)
lab = await self.get_resource(Lab)
app = await self.get(App)
auth = await self.get(Auth)
frontend_config = await self.get(FrontendConfig)
lab = await self.get(Lab)

jupyterlab = _JupyterLab(app, self.jupyterlab_config, auth, frontend_config, lab)
self.add_resource(jupyterlab, types=JupyterLab)

self.done()
self.put(jupyterlab, types=JupyterLab)
4 changes: 2 additions & 2 deletions plugins/jupyterlab/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ ignore = [ ".*",]
skip = [ "check-links",]

[project.entry-points]
"fastaio.components" = {jupyterlab = "fps_jupyterlab.main:JupyterLabComponent"}
"jupyverse.components" = {jupyterlab = "fps_jupyterlab.main:JupyterLabComponent"}
"fastaio.modules" = {jupyterlab = "fps_jupyterlab.main:JupyterLabModule"}
"jupyverse.modules" = {jupyterlab = "fps_jupyterlab.main:JupyterLabModule"}

[tool.hatch.version]
path = "fps_jupyterlab/__init__.py"
1 change: 0 additions & 1 deletion plugins/kernels/MANIFEST.in

This file was deleted.

Loading

0 comments on commit 2979400

Please sign in to comment.