-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (125 loc) · 4.96 KB
/
Makefile
File metadata and controls
153 lines (125 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
PYTHON_VERSION ?= 3.10
.PHONY: help
help: ## 显示帮助文件
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: setup-hooks
setup-hooks: ## 配置 pre-commit hooks
@echo "Setting up pre-commit hooks..."
@if [ ! -d ".git" ]; then \
echo "⚠️ Not a Git repository, skipping hooks installation"; \
else \
git config --local core.hooksPath "./scripts/githooks" ; \
echo "✅ Git pre-commit hook installed (linked to scripts/pre-commit)"; \
fi
.PHONY: fmt
fmt:
@uv run isort agentrun
@uv run isort tests
@uv run isort examples
@uv run find -L ./agentrun -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
@uv run find -L ./tests -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
@uv run find -L ./examples -not -path "*/.*" -type f -name "*.py" -exec pyink --config pyproject.toml {} +
# 只格式化指定的文件
.PHONY: fmt-file
fmt-file:
@if [ -z "$(FMT_FILE)" ]; then \
echo "Usage: make fmt-file FMT_FILE=path/to/file.py"; \
exit 1; \
fi
@if [ -f "$(FMT_FILE)" ]; then \
echo "Formatting $(FMT_FILE)"; \
uv run isort "$(FMT_FILE)"; \
uv run pyink --config pyproject.toml "$(FMT_FILE)"; \
else \
echo "File $(FMT_FILE) does not exist"; \
exit 1; \
fi
JINJA2_FILES := \
agentrun/agent_runtime/api/control.py \
agentrun/credential/api/control.py \
agentrun/model/api/control.py \
agentrun/toolset/api/control.py \
agentrun/sandbox/api/control.py \
agentrun/memory_collection/api/control.py
JINJA2_CONFIGS := \
codegen/configs/agent_runtime_control_api.yaml \
codegen/configs/credential_control_api.yaml \
codegen/configs/model_control_api.yaml \
codegen/configs/toolset_control_api.yaml \
codegen/configs/sandbox_control_api.yaml \
codegen/configs/memory_collection_control_api.yaml \
define make_jinja2_rule
$(1): $(2)
@echo "Generating $$@ from $$<"
@uv run python3 codegen/codegen.py --jinja2-only --config "$$<"
endef
# 应用 Jinja2 规则
$(eval $(call make_jinja2_rule,agentrun/agent_runtime/api/control.py,codegen/configs/agent_runtime_control_api.yaml))
$(eval $(call make_jinja2_rule,agentrun/credential/api/control.py,codegen/configs/credential_control_api.yaml))
$(eval $(call make_jinja2_rule,agentrun/model/api/control.py,codegen/configs/model_control_api.yaml))
$(eval $(call make_jinja2_rule,agentrun/toolset/api/control.py,codegen/configs/toolset_control_api.yaml))
$(eval $(call make_jinja2_rule,agentrun/sandbox/api/control.py,codegen/configs/sandbox_control_api.yaml))
$(eval $(call make_jinja2_rule,agentrun/memory_collection/api/control.py,codegen/configs/memory_collection_control_api.yaml))
TEMPLATE_FILES := $(shell find . -name "__*async_template.py" -not -path "*__pycache__*" -not -path "*egg-info*")
# 根据模板文件生成对应的输出文件路径
define template_to_output
$(patsubst ./%,%,$(subst __,,$(subst _async_template.py,.py,$1)))
endef
# 生成所有输出文件的列表
SYNC_FILES := $(foreach template,$(TEMPLATE_FILES),$(call template_to_output,$(template)))
# 为每个模板文件创建依赖关系规则
define make_sync_rule
$(call template_to_output,$1): $1
@echo "Generating $$@ from $$<"
@uv run python3 codegen/codegen.py --sync-only --template "$$<"
@make fmt-file FMT_FILE="$$<"
endef
# 应用规则到所有模板文件
$(foreach template,$(TEMPLATE_FILES),$(eval $(call make_sync_rule,$(template))))
.PHONY: codegen
codegen: $(JINJA2_FILES) $(SYNC_FILES) ## 生成代码
.PHONY: sync_codegen
sync_codegen:
@uv run python3 codegen/codegen.py --sync-only
@uv run codegen/codegen.py --sync-only
.PHONY: codegen_file
codegen_file:
@uv run python3 codegen/codegen.py --jinja2-only
.PHONY: codegen-all
codegen-all: sync_codegen codegen_file fmt ## 强制重新生成所有代码
.PHONY: setup
setup: install-uv install-deps setup-hooks
.PHONY: install-uv
install-uv: ## Check and install uv
@if command -v uv >/dev/null 2>&1; then \
echo "✅ uv is already installed: $$(uv --version)"; \
else \
pip install uv; \
fi
.PHONY: install-deps
install-deps:
command -v uv >/dev/null 2>&1 && \
uv sync \
--python ${PYTHON_VERSION} \
--dev \
--all-extras \
-i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
# ============================================================================
# 测试和覆盖率
# ============================================================================
.PHONY: test
test: ## 运行所有测试
@uv run pytest tests/
.PHONY: test-unit
test-unit: ## 运行单元测试
@uv run pytest tests/unittests/
.PHONY: test-e2e
test-e2e: ## 运行端到端测试
@uv run pytest tests/e2e/
.PHONY: mypy-check
mypy-check: ## 运行 mypy 类型检查
@uv run mypy --config-file mypy.ini .
.PHONY: coverage
coverage: ## 运行测试并显示覆盖率报告(全量代码 + 增量代码)
@echo "📊 运行覆盖率测试..."
@uv run --python ${PYTHON_VERSION} --all-extras python scripts/check_coverage.py $(COVERAGE_ARGS)