基于 python3.8 的新 api server
python 版本: 3.8
使用poetry进行依赖管理。
git clone https://github.com/bangumi/server bangumi-server
cd bangumi-server进入虚拟环境
python -m venv .venv # MUST use python 3.8
source .venv/bin/activate # enable virtualenv安装依赖
poetry install --remove-untracked安装 git hook
pre-commit install可设置的环境变量
MYSQL_HOST默认127.0.0.1MYSQL_PORT默认3306MYSQL_DB默认bangumiMYSQL_USER无默认值MYSQL_PASS无默认值
Web 框架 fastapi
ORM 类定义在 pol/db/tables.py 文件。
路由位于 pol/api 文件夹。
https://github.com/bangumi/dev-env
启动开发服务器
uvicorn pol.server:app --reload --port 3000测试基于 pytest
pytest参照 tests/app/test_base_router.py 文件。在测试函数中添加client参数获取对应的 HTTP 测试客户端。client 是一个 requests.Session 的实例,可以使用 requests 的各种函数参数。
以 LF 为换行符
启用 pre-commit
pre-commit installpre-commit 会在当前仓库安装一个 git hook,在每次 commit 前自动运行。
也可以手动运行
pre-commit run #only check changed files
pre-commit run --all-files # check all fileslint: flake8
非 python 文件(yaml, json, markdown 等)使用 prettier 进行格式化。
pol 来源于我的旧项目名,没有特殊含义。
BSD 3-Clause License