统一服务启动入口至 Makefile(dev-core/dev-*/db-*/test-*),Alembic 迁移改为 000 起三位顺序编号并经 make db-revision 生成
This commit is contained in:
1 parent
8ebcc11a8a
commit
c090893e63
8 files changed
+162
-50
No files matched your search
@@ -1,30 +1,142 @@
|
||||
# Makefile for cleaning Python cache files and empty directories
|
||||
# Author: AI Assistant
|
||||
# Usage: make clean or make clean-all
|
||||
# ==============================
|
||||
# 魂镜 · 统一开发入口(rewrite/1.0)
|
||||
# 所有本地服务的启动 / 测试 / 数据库迁移统一经本文件;
|
||||
# Docker 编排(基础设施与应用容器)见 AGENTS.md「开发命令」与 docker/README.md。
|
||||
# ==============================
|
||||
|
||||
.PHONY: clean clean-all clean-pyc clean-pytest clean-mypy clean-empty-dirs help
|
||||
|
||||
# Colors for pretty output
|
||||
GREEN := \033[0;32m
|
||||
YELLOW := \033[0;33m
|
||||
RED := \033[0;31m
|
||||
NC := \033[0m # No Color
|
||||
NC := \033[0m
|
||||
|
||||
# Default target
|
||||
.PHONY: help \
|
||||
dev-backend dev-shenshi dev-bff dev-frontend dev-sandbox dev-tianmu dev-yuanqi dev-core dev-all \
|
||||
db-upgrade db-downgrade db-revision db-current \
|
||||
test test-backend test-shenshi test-bff test-frontend \
|
||||
vet-shenshi typecheck-bff \
|
||||
infra-up app-up app-down \
|
||||
clean clean-all clean-pyc clean-pytest clean-mypy clean-empty-dirs clean-dry-run
|
||||
|
||||
# 默认目标
|
||||
help:
|
||||
@echo "$(GREEN)Available targets:$(NC)"
|
||||
@echo " $(YELLOW)make clean$(NC) - Remove Python cache files, pytest cache, mypy cache, and empty directories"
|
||||
@echo " $(YELLOW)make clean-pyc$(NC) - Remove Python cache files (__pycache__, .pyc, .pyo)"
|
||||
@echo " $(YELLOW)make clean-pytest$(NC) - Remove pytest cache (.pytest_cache)"
|
||||
@echo " $(YELLOW)make clean-mypy$(NC) - Remove mypy cache (.mypy_cache)"
|
||||
@echo " $(YELLOW)make clean-empty-dirs$(NC) - Remove empty directories"
|
||||
@echo " $(YELLOW)make clean-all$(NC) - Remove everything (cache, logs, coverage, build, dist, etc.)"
|
||||
@echo "$(GREEN)魂镜统一开发入口$(NC)"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)服务启动(开发)$(NC)"
|
||||
@echo " make dev-backend 灵台(uvicorn 热重载,:8000)"
|
||||
@echo " make dev-shenshi 神识(go run,:8080)"
|
||||
@echo " make dev-bff 照壁(tsx watch,:3000)"
|
||||
@echo " make dev-frontend 琉璃镜(next dev,:3001)"
|
||||
@echo " make dev-sandbox 乾坤沙箱(cargo run,:8090)"
|
||||
@echo " make dev-tianmu 天目 OCR(:8101,可选)"
|
||||
@echo " make dev-yuanqi 元炁本地推理(:11434,可选)"
|
||||
@echo " make dev-core 核心三服务并行(灵台+神识+照壁)"
|
||||
@echo " make dev-all 前述全部并行(不含沙箱/天目/元炁)"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)数据库(Alembic,迁移编号 000/001/002…)$(NC)"
|
||||
@echo " make db-upgrade 升级到最新(head)"
|
||||
@echo " make db-downgrade 回退一步"
|
||||
@echo " make db-revision m=\"说明\" 生成下一号迁移(自动编号+autogenerate)"
|
||||
@echo " make db-current 查看当前版本"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)测试与检查$(NC)"
|
||||
@echo " make test 全部(后端+神识+照壁+前端)"
|
||||
@echo " make test-backend / test-shenshi / test-bff / test-frontend"
|
||||
@echo " make vet-shenshi go vet"
|
||||
@echo " make typecheck-bff tsc --noEmit"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)Docker 编排快捷方式$(NC)"
|
||||
@echo " make infra-up / app-up / app-down"
|
||||
@echo ""
|
||||
@echo "$(YELLOW)清理$(NC)"
|
||||
@echo " make clean / clean-all / clean-dry-run"
|
||||
|
||||
# ============================== 服务启动(开发) ==============================
|
||||
|
||||
dev-backend:
|
||||
cd backend && uv run python -m app.main
|
||||
|
||||
dev-shenshi:
|
||||
cd shenshi && go run .
|
||||
|
||||
dev-bff:
|
||||
cd bff && npm run dev
|
||||
|
||||
dev-frontend:
|
||||
cd frontend && pnpm dev
|
||||
|
||||
dev-sandbox:
|
||||
cd sandbox && cargo run
|
||||
|
||||
dev-tianmu:
|
||||
cd tianmu && uv run python -m src.main
|
||||
|
||||
dev-yuanqi:
|
||||
cd yuanqi && uv run python -m src.main
|
||||
|
||||
# 核心三服务并行:灵台 + 神识 + 照壁(M0 验收链路)
|
||||
dev-core:
|
||||
$(MAKE) -j3 dev-backend dev-shenshi dev-bff
|
||||
|
||||
dev-all:
|
||||
$(MAKE) -j4 dev-backend dev-shenshi dev-bff dev-frontend
|
||||
|
||||
# ============================== 数据库(Alembic) ==============================
|
||||
|
||||
# 迁移约定:revision id 与文件名前缀用三位顺序号(000、001、002…),生成统一走
|
||||
# `make db-revision`(自动取最大号+1 并传 --rev-id);不要手写哈希 id。
|
||||
db-upgrade:
|
||||
cd backend && uv run alembic upgrade head
|
||||
|
||||
db-downgrade:
|
||||
cd backend && uv run alembic downgrade -1
|
||||
|
||||
db-revision:
|
||||
@next=$$(ls backend/alembic/versions 2>/dev/null | grep -E '^[0-9][0-9][0-9]_.*\.py$$' | cut -c1-3 | sort -n | tail -1); \
|
||||
if [ -z "$$next" ]; then echo "未找到顺序编号迁移,请先确认基线 000 存在"; exit 1; fi; \
|
||||
next=$$(printf '%03d' $$((10#$$next + 1))); \
|
||||
echo "$(GREEN)生成迁移 $(NC)$$next:$(m)"; \
|
||||
cd backend && uv run alembic revision --autogenerate --rev-id $$next -m "$(m)"
|
||||
|
||||
db-current:
|
||||
cd backend && uv run alembic current
|
||||
|
||||
# ============================== 测试与检查 ==============================
|
||||
|
||||
test-backend:
|
||||
cd backend && uv run pytest -q
|
||||
|
||||
test-shenshi:
|
||||
cd shenshi && go test ./...
|
||||
|
||||
test-bff:
|
||||
cd bff && npm test --silent
|
||||
|
||||
test-frontend:
|
||||
cd frontend && pnpm test
|
||||
|
||||
test: test-backend test-shenshi test-bff test-frontend
|
||||
|
||||
vet-shenshi:
|
||||
cd shenshi && go vet ./...
|
||||
|
||||
typecheck-bff:
|
||||
cd bff && npm run type-check --silent
|
||||
|
||||
# ============================== Docker 编排快捷方式 ==============================
|
||||
|
||||
infra-up:
|
||||
docker compose -f docker/docker-compose.infra.yml up -d
|
||||
|
||||
app-up:
|
||||
docker compose -f docker/docker-compose.app.yml up -d --build
|
||||
|
||||
app-down:
|
||||
docker compose -f docker/docker-compose.app.yml down
|
||||
|
||||
# ============================== 清理(保留原有能力) ==============================
|
||||
|
||||
# Main clean target
|
||||
clean: clean-pyc clean-pytest clean-mypy clean-empty-dirs
|
||||
@echo "$(GREEN)✓ Cleanup completed successfully!$(NC)"
|
||||
|
||||
# Clean Python cache files
|
||||
clean-pyc:
|
||||
@echo "$(YELLOW)Removing Python cache files...$(NC)"
|
||||
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
||||
@@ -33,55 +145,35 @@ clean-pyc:
|
||||
@find . -type f -name "*.pyd" -delete 2>/dev/null || true
|
||||
@echo "$(GREEN)✓ Python cache files removed$(NC)"
|
||||
|
||||
# Clean pytest cache
|
||||
clean-pytest:
|
||||
@echo "$(YELLOW)Removing pytest cache...$(NC)"
|
||||
@rm -rf .pytest_cache 2>/dev/null || true
|
||||
@find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
|
||||
@echo "$(GREEN)✓ Pytest cache removed$(NC)"
|
||||
|
||||
# Clean mypy cache
|
||||
clean-mypy:
|
||||
@echo "$(YELLOW)Removing mypy cache...$(NC)"
|
||||
@rm -rf .mypy_cache 2>/dev/null || true
|
||||
@find . -type d -name ".mypy_cache" -exec rm -rf {} + 2>/dev/null || true
|
||||
@echo "$(GREEN)✓ Mypy cache removed$(NC)"
|
||||
|
||||
# Remove empty directories
|
||||
clean-empty-dirs:
|
||||
@echo "$(YELLOW)Removing empty directories...$(NC)"
|
||||
@# Remove empty directories (including hidden ones), excluding .git and .venv
|
||||
@find . -type d -empty -not -path "./.git/*" -not -path "./.venv/*" -not -path "./venv/*" -not -path "./env/*" -not -path "./.env/*" -delete 2>/dev/null || true
|
||||
@# Second pass to remove newly created empty parent directories
|
||||
@find . -type d -empty -not -path "./.git/*" -not -path "./.venv/*" -not -path "./venv/*" -not -path "./env/*" -not -path "./.env/*" -delete 2>/dev/null || true
|
||||
@echo "$(GREEN)✓ Empty directories removed$(NC)"
|
||||
|
||||
# Clean everything (extended cleanup)
|
||||
clean-all: clean
|
||||
@echo "$(YELLOW)Removing additional files...$(NC)"
|
||||
@# Coverage reports
|
||||
@rm -rf htmlcov .coverage coverage.xml .coverage.* 2>/dev/null || true
|
||||
@# Build artifacts
|
||||
@rm -rf build/ dist/ *.egg-info .eggs/ 2>/dev/null || true
|
||||
@# Log files
|
||||
@find . -type f -name "*.log" -delete 2>/dev/null || true
|
||||
@# Jupyter notebooks checkpoint
|
||||
@find . -type d -name ".ipynb_checkpoints" -exec rm -rf {} + 2>/dev/null || true
|
||||
@# IDE files (optional, uncomment if needed)
|
||||
# @rm -rf .vscode/ .idea/ 2>/dev/null || true
|
||||
@echo "$(GREEN)✓ Extended cleanup completed!$(NC)"
|
||||
|
||||
# Dry run - show what would be deleted (for safety)
|
||||
clean-dry-run:
|
||||
@echo "$(YELLOW)Dry run - files that would be deleted:$(NC)"
|
||||
@echo "\nPython cache files:"
|
||||
@echo "$(YELLOW)Dry run - files that would be deleted (run 'make clean' to delete):$(NC)"
|
||||
@find . -type d -name "__pycache__" 2>/dev/null || echo "None"
|
||||
@find . -type f -name "*.pyc" 2>/dev/null || echo "None"
|
||||
@find . -type f -name "*.pyo" 2>/dev/null || echo "None"
|
||||
@echo "\nPytest cache:"
|
||||
@find . -type d -name ".pytest_cache" 2>/dev/null || echo "None"
|
||||
@echo "\nMypy cache:"
|
||||
@find . -type d -name ".mypy_cache" 2>/dev/null || echo "None"
|
||||
@echo "\nEmpty directories:"
|
||||
@find . -type d -empty -not -path "./.git/*" -not -path "./.venv/*" 2>/dev/null || echo "None"
|
||||
@echo "$(YELLOW)\nRun 'make clean' to actually delete these files$(NC)"
|
||||
Reference in new issue
Block a user