v0.1.1 项目结构与构建流程更新

涉及的文件很多,但主要是 PyCharm 自动重构 + 手动微调。

1. 使用 src-layout 结构组织项目,旨在更加规范地管理各个子包,并方便组织代码。
2. 可以使用 uv build 构建项目至 wheel。
3. 可以在 /webui 目录下使用 pnpm run build 来构建 WebUI,构建产物会生成在
/src/njupt_suan_api/static 目录下。同时,uv build 时会一同包含此目录下的 WebUI
构建产物,避免在用户侧执行构建。
4. 使用 typer 实现了命令行入口,代码位于 manage.py;命令行实现了现 main.py 的全部功能。
This commit is contained in:
2026-04-25 21:30:11 +08:00
parent 8db1d27758
commit 247d9f089c
44 changed files with 306 additions and 187 deletions

View File

@@ -0,0 +1,24 @@
from pathlib import Path
import aiofiles
from fastapi import APIRouter
from fastapi.responses import HTMLResponse
STATIC_DIR = Path(__file__).parent.parent / "static"
WEBUI_INDEX = STATIC_DIR / "index.html"
SCHEDULE_INDEX = STATIC_DIR / "index-schedule.html"
ASSETS_DIR = STATIC_DIR / "assets"
webui_router = APIRouter(prefix="/webui")
@webui_router.get("/", response_class=HTMLResponse)
async def get_webui() -> HTMLResponse:
async with aiofiles.open(file=WEBUI_INDEX, mode="r", encoding="utf-8") as f:
return HTMLResponse(content=await f.read(), status_code=200)
@webui_router.get("/schedule", response_class=HTMLResponse)
async def get_webui_schedule() -> HTMLResponse:
async with aiofiles.open(file=SCHEDULE_INDEX, mode="r", encoding="utf-8") as f:
return HTMLResponse(content=await f.read(), status_code=200)