Files
2026-09-12 20:12:36 +08:00

75 lines
2.5 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# DjangoAdmin Flask 常用命令集
# 用法:make help / make lint / make test / ...
# ============================================================
PYTHON ?= python
PIP ?= $(PYTHON) -m pip
FLASK ?= $(PYTHON) -m flask
# 说明:.env 中 FLASK_VERSION=v3.0.0 会被 Flask CLI 误解析为 --version 布尔标志,
# 导致 flask db 系列命令报错。故 db-* 目标显式跳过 CLI 自动加载 .env
# (config/__init__.py 会自行加载 .env,应用配置不受影响)。
FLASK_ENV_PREFIX := FLASK_SKIP_DOTENV=1 FLASK_APP=app.py
.PHONY: help install install-dev dev lint format type-check test test-cov \
db-migrate db-upgrade db-downgrade docker-up docker-down clean
help: ## 显示全部命令帮助
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
# ---- 依赖 ----
install: ## 安装生产依赖
$(PIP) install -r requirements.txt
install-dev: ## 安装开发依赖(含生产依赖 + 测试/规范工具)
$(PIP) install -r requirements-dev.txt
# ---- 运行 ----
dev: ## 启动开发服务器(127.0.0.1:8021)
$(PYTHON) app.py
# ---- 代码质量 ----
lint: ## 静态检查(flake8 + black + isort)
flake8 src config tests scripts
black --check --line-length 120 src config tests scripts
isort --check-only src config tests scripts
format: ## 自动格式化(black + isort)
black --line-length 120 src config tests scripts
isort src config tests scripts
type-check: ## 类型检查(mypy)
mypy src
# ---- 测试 ----
test: ## 运行全部测试
pytest
test-cov: ## 带覆盖率运行测试
pytest --cov=src --cov-report=term-missing
# ---- 数据库迁移 ----
db-migrate: ## 生成迁移脚本(模型变更后)
$(FLASK_ENV_PREFIX) $(FLASK) db migrate
db-upgrade: ## 应用迁移到最新
$(FLASK_ENV_PREFIX) $(FLASK) db upgrade
db-downgrade: ## 回滚一次迁移
$(FLASK_ENV_PREFIX) $(FLASK) db downgrade
# ---- Docker ----
docker-up: ## 启动 Docker 服务
cd docker && docker-compose up -d
docker-down: ## 停止 Docker 服务
cd docker && docker-compose down
# ---- 清理 ----
clean: ## 清理缓存与临时文件
find . -type d -name __pycache__ -not -path "*/ui/*" -exec rm -rf {} +
find . -type f -name "*.pyc" -not -path "*/ui/*" -delete
rm -rf .pytest_cache .mypy_cache