From acc648fc6b8c78d31c801d133bb66a3497c83d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 23 Aug 2023 17:17:34 +0200 Subject: [PATCH 1/2] integrate webserver into cli integrate webserver into cli --- pkgs/clan-cli/clan_cli/webui/app.py | 7 +++++++ pkgs/clan-cli/clan_cli/webui/routers/__init__.py | 0 pkgs/clan-cli/clan_cli/webui/routers/health.py | 8 ++++++++ pkgs/clan-cli/clan_cli/webui/routers/root.py | 9 +++++++++ pkgs/clan-cli/clan_cli/webui/server.py | 11 +---------- 5 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 pkgs/clan-cli/clan_cli/webui/app.py create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/__init__.py create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/health.py create mode 100644 pkgs/clan-cli/clan_cli/webui/routers/root.py diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py new file mode 100644 index 000000000..52de7cc1b --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -0,0 +1,7 @@ +from fastapi import FastAPI + +from .routers import health, root + +app = FastAPI() +app.include_router(health.router) +app.include_router(root.router) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/__init__.py b/pkgs/clan-cli/clan_cli/webui/routers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pkgs/clan-cli/clan_cli/webui/routers/health.py b/pkgs/clan-cli/clan_cli/webui/routers/health.py new file mode 100644 index 000000000..d734e121e --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/health.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/health") +async def health() -> str: + return "OK" diff --git a/pkgs/clan-cli/clan_cli/webui/routers/root.py b/pkgs/clan-cli/clan_cli/webui/routers/root.py new file mode 100644 index 000000000..752b6e726 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/webui/routers/root.py @@ -0,0 +1,9 @@ +from fastapi import APIRouter, Response + +router = APIRouter() + + +@router.get("/") +async def root() -> Response: + body = "

Welcome

" + return Response(content=body, media_type="text/html") diff --git a/pkgs/clan-cli/clan_cli/webui/server.py b/pkgs/clan-cli/clan_cli/webui/server.py index 7205496bc..cbea5a215 100644 --- a/pkgs/clan-cli/clan_cli/webui/server.py +++ b/pkgs/clan-cli/clan_cli/webui/server.py @@ -4,18 +4,9 @@ import urllib.request import webbrowser from threading import Thread -from fastapi import FastAPI - # XXX: can we dynamically load this using nix develop? from uvicorn import run -app = FastAPI() - - -@app.get("/health") -async def read_root() -> str: - return "OK" - def defer_open_browser(base_url: str) -> None: for i in range(5): @@ -33,7 +24,7 @@ def start_server(args: argparse.Namespace) -> None: target=defer_open_browser, args=(f"http://[{args.host}]:{args.port}",) ).start() run( - "clan_cli.webui.server:app", + "clan_cli.webui.app:app", host=args.host, port=args.port, log_level=args.log_level, From 745368242d9d94b8becff302b151dd46f63f262e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 24 Aug 2023 11:30:19 +0200 Subject: [PATCH 2/2] pre-commit: don't fail silent if mypy fails we don't know why --- scripts/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 61b1010ea..5760641b8 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -46,7 +46,7 @@ git stash push --quiet --keep-index --message "treefmt pre-commit" trap restore_stash EXIT # Run treefmt on the files in the index and record the result. -nix fmt -- --no-cache --quiet "${commit_files[@]}" +nix fmt -- --no-cache "${commit_files[@]}" # Check if there is a diff git diff --name-only --exit-code