Skip to content

Commit

Permalink
remove fastapi, use starlette directly (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrodnek authored May 17, 2024
1 parent 07dc28b commit f9668b5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 603 deletions.
4 changes: 2 additions & 2 deletions examples/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from starlette.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
from starlette.routing import Route
from pyview import PyView, defaultRootTemplate
from markupsafe import Markup
Expand Down
592 changes: 2 additions & 590 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.9.16"
fastapi = "0.111.0"
python = ">=3.9,<3.12"
starlette = "0.37.2"
uvicorn = "0.20.0"
wsproto = "1.2.0"
APScheduler = "3.9.1.post1"
psutil = "^5.9.4"
markupsafe = "^2.1.2"
itsdangerous = "^2.1.2"
pydantic = "^2.7.1"

[tool.poetry.group.dev.dependencies]
pytest = "^6.0.0"
Expand Down
12 changes: 9 additions & 3 deletions pyview/live_socket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from fastapi import WebSocket
from starlette.websockets import WebSocket
import json
from typing import Any, TypeVar, Generic, TYPE_CHECKING, Optional
from urllib.parse import urlencode
Expand Down Expand Up @@ -49,12 +49,18 @@ async def _topic_callback_internal(self, topic, message):

def schedule_info(self, event, seconds):
id = f"{self.topic}:{event}"
scheduler.add_job(self.send_info, args=[event], id=id, trigger="interval", seconds=seconds)
scheduler.add_job(
self.send_info, args=[event], id=id, trigger="interval", seconds=seconds
)
self.scheduled_jobs.append(id)

def schedule_info_once(self, event):
scheduler.add_job(
self.send_info, args=[event], trigger="date", run_date=datetime.datetime.now(), misfire_grace_time=None
self.send_info,
args=[event],
trigger="date",
run_date=datetime.datetime.now(),
misfire_grace_time=None,
)

def diff(self, render: dict[str, Any]) -> dict[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions pyview/pyview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from starlette.applications import Starlette
from fastapi import WebSocket
from fastapi.responses import HTMLResponse
from starlette.websockets import WebSocket
from starlette.responses import HTMLResponse
from starlette.middleware.gzip import GZipMiddleware
from starlette.routing import Route
from starlette.requests import Request
Expand Down
14 changes: 10 additions & 4 deletions pyview/ws_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from fastapi import WebSocket, WebSocketDisconnect
import json
from starlette.websockets import WebSocket, WebSocketDisconnect
from urllib.parse import urlparse, parse_qs
from pyview.live_socket import LiveViewSocket
from pyview.live_routes import LiveViewLookup
Expand Down Expand Up @@ -83,7 +83,9 @@ async def handle_connected(self, socket: LiveViewSocket):
"phx_reply",
{"response": {}, "status": "ok"},
]
await self.manager.send_personal_message(json.dumps(resp), socket.websocket)
await self.manager.send_personal_message(
json.dumps(resp), socket.websocket
)
continue

if event == "event":
Expand All @@ -101,7 +103,9 @@ async def handle_connected(self, socket: LiveViewSocket):
"phx_reply",
{"response": {"diff": rendered}, "status": "ok"},
]
await self.manager.send_personal_message(json.dumps(resp), socket.websocket)
await self.manager.send_personal_message(
json.dumps(resp), socket.websocket
)
continue

if event == "live_patch":
Expand All @@ -118,7 +122,9 @@ async def handle_connected(self, socket: LiveViewSocket):
"phx_reply",
{"response": {"diff": rendered}, "status": "ok"},
]
await self.manager.send_personal_message(json.dumps(resp), socket.websocket)
await self.manager.send_personal_message(
json.dumps(resp), socket.websocket
)
continue


Expand Down

0 comments on commit f9668b5

Please sign in to comment.