.PHONY: help install run test clean format lint db-migrate db-upgrade db-downgrade # 默认目标 help: @echo "可用命令:" @echo " make install - 安装依赖" @echo " make run - 启动开发服务器" @echo " make test - 运行测试" @echo " make clean - 清理缓存和临时文件" @echo " make format - 格式化代码" @echo " make lint - 代码检查" @echo " make db-migrate - 创建数据库迁移" @echo " make db-upgrade - 执行数据库迁移" @echo " make db-downgrade - 回滚数据库迁移" # 安装依赖 install: pip install -r requirements.txt # 启动开发服务器 run: python run.py # 运行测试 test: pytest tests/ -v --cov=app --cov-report=html # 清理缓存和临时文件 clean: find . -type d -name "__pycache__" -exec rm -rf {} + find . -type f -name "*.pyc" -delete find . -type f -name "*.pyo" -delete find . -type f -name "*.pyd" -delete rm -rf .pytest_cache rm -rf htmlcov rm -rf .mypy_cache rm -rf .coverage # 格式化代码 format: black app/ tests/ isort app/ tests/ # 代码检查 lint: flake8 app/ tests/ mypy app/ # 创建数据库迁移 db-migrate: @read -p "请输入迁移描述: " desc; \ alembic revision --autogenerate -m "$$desc" # 执行数据库迁移 db-upgrade: alembic upgrade head # 回滚数据库迁移 db-downgrade: alembic downgrade -1