Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (108 loc) · 6.91 KB
/
Copy pathMakefile
File metadata and controls
131 lines (108 loc) · 6.91 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
.DEFAULT_GOAL := all
.PHONY: .uv
.uv: ## Check that uv is installed
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'
.PHONY: install
install: .uv ## Install the package, dependencies, and pre-commit for local development
uv sync --frozen --all-extras --no-extra mcp-tasks --all-packages --group lint
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit install --install-hooks; \
else \
uv tool install pre-commit && "$$(uv tool dir --bin)/pre-commit" install --install-hooks; \
fi
.PHONY: install-all-python
install-all-python: ## Install and synchronize an interpreter for every python version
UV_PROJECT_ENVIRONMENT=.venv311 uv sync --python 3.11 --frozen --all-extras --no-extra mcp-tasks --all-packages --group lint
UV_PROJECT_ENVIRONMENT=.venv312 uv sync --python 3.12 --frozen --all-extras --no-extra mcp-tasks --all-packages --group lint
UV_PROJECT_ENVIRONMENT=.venv313 uv sync --python 3.13 --frozen --all-extras --no-extra mcp-tasks --all-packages --group lint
UV_PROJECT_ENVIRONMENT=.venv314 uv sync --python 3.14 --frozen --all-extras --no-extra mcp-tasks --all-packages --group lint
.PHONY: sync
sync: .uv ## Update local packages and uv.lock
uv sync --all-extras --no-extra mcp-tasks --all-packages --group lint
.PHONY: format
format: ## Format the code
uv run ruff format
uv run ruff check --fix --fix-only
.PHONY: lint
lint: ## Lint the code
uv run ruff format --check
uv run ruff check
# Worker processes for pyright's check phase, all producing identical output. Unset is pyright's own
# single-process check, and so is 1; 'auto' is up to one worker per logical core and a positive
# integer caps them. Anything else pyright cannot read as a positive integer, 0 and 'off' included,
# means 'auto' -- pyright's parseThreadsArgValue: https://github.com/microsoft/pyright/blob/1.1.411/packages/pyright-internal/src/pyright.ts#L1366-L1377
# See docs/contributing.md for when the workers pay for themselves.
PYRIGHT_THREADS ?=
.PHONY: typecheck-pyright
typecheck-pyright:
@# To typecheck for a specific version of python, run 'make install-all-python' then set environment variable PYRIGHT_PYTHON=3.11 or similar
@# PYRIGHT_PYTHON_IGNORE_WARNINGS avoids the overhead of making a request to github on every invocation
PYRIGHT_PYTHON_IGNORE_WARNINGS=1 uv run pyright $(if $(PYRIGHT_THREADS),--threads $(PYRIGHT_THREADS)) $(if $(PYRIGHT_PYTHON),--pythonversion $(PYRIGHT_PYTHON))
@# Pyright skips everything under a dot directory, so `.github/scripts` is a project of its own
PYRIGHT_PYTHON_IGNORE_WARNINGS=1 uv run pyright -p .github/scripts $(if $(PYRIGHT_THREADS),--threads $(PYRIGHT_THREADS)) $(if $(PYRIGHT_PYTHON),--pythonversion $(PYRIGHT_PYTHON))
.PHONY: typecheck-changed
typecheck-changed: ## Run static type checking on the files reached by changes since it last passed
@# CI's Pyright entry point. Locally, whenever the narrowed set is not provably the same answer, it
@# runs pyright over every tracked file it reports on, minus the unchanged `tests/` files. Only `CI`, an
@# interpreter older than 3.11 and a pyright configuration it cannot reproduce hand the whole project to
@# `typecheck-pyright`; see scripts/typecheck_changed.py
uv run python scripts/typecheck_changed.py
.PHONY: typecheck-mypy
typecheck-mypy:
uv run mypy
.PHONY: typecheck
typecheck: typecheck-pyright ## Run static type checking
.PHONY: typecheck-both ## Run static type checking with both Pyright and Mypy
typecheck-both: typecheck-pyright typecheck-mypy
.PHONY: test
test: ## Run tests without coverage (fast, for local dev)
@# To test using a specific version of python, run 'make install-all-python' then set environment variable PYTEST_PYTHON=3.11 or similar
COLUMNS=150 $(if $(PYTEST_PYTHON),UV_PROJECT_ENVIRONMENT=.venv$(subst .,,$(PYTEST_PYTHON))) uv run $(if $(PYTEST_PYTHON),--python $(PYTEST_PYTHON)) pytest -n auto --dist=loadgroup --durations=20
.PHONY: test-all-python
test-all-python: ## Run tests on Python 3.11 to 3.14
COLUMNS=150 UV_PROJECT_ENVIRONMENT=.venv311 uv run --python 3.11 --all-extras --no-extra mcp-tasks --all-packages coverage run -p -m pytest
COLUMNS=150 UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 --all-extras --no-extra mcp-tasks --all-packages coverage run -p -m pytest
COLUMNS=150 UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 --all-extras --no-extra mcp-tasks --all-packages coverage run -p -m pytest
COLUMNS=150 UV_PROJECT_ENVIRONMENT=.venv314 uv run --python 3.14 --all-extras --no-extra mcp-tasks --all-packages coverage run -p -m pytest
@uv run coverage combine
@uv run coverage report
.PHONY: testcov
testcov: ## Run tests with coverage and generate an HTML report
@# To test using a specific version of python, run 'make install-all-python' then set environment variable PYTEST_PYTHON=3.11 or similar
COLUMNS=150 $(if $(PYTEST_PYTHON),UV_PROJECT_ENVIRONMENT=.venv$(subst .,,$(PYTEST_PYTHON))) uv run $(if $(PYTEST_PYTHON),--python $(PYTEST_PYTHON)) coverage run -m pytest -n auto --dist=loadgroup --durations=20
@uv run coverage combine
@uv run coverage report
@echo "building coverage html"
@uv run coverage html
.PHONY: integration-localstack
integration-localstack: ## Run the harness LocalStack tests (needs Docker and LOCALSTACK_AUTH_TOKEN)
uv run --all-packages --all-extras --no-extra mcp-tasks pytest src/pydantic_ai_harness/integration_tests/localstack
.PHONY: integration-mongodb
integration-mongodb: ## Run the harness MongoDB tests (`docker run -d -p 27017:27017 mongo:8`, or set MONGODB_TEST_URL)
uv run --all-packages --all-extras --no-extra mcp-tasks pytest src/pydantic_ai_harness/integration_tests/mongodb
.PHONY: integration-postgres
integration-postgres: ## Run the harness Postgres tests (`docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:17`, or set POSTGRES_TEST_URL)
uv run --all-packages --all-extras --no-extra mcp-tasks pytest src/pydantic_ai_harness/integration_tests/postgres
.PHONY: integration-redis
integration-redis: ## Run the harness Redis tests (`docker run -d -p 6379:6379 redis:8`, or set REDIS_TEST_URL)
uv run --all-packages --all-extras --no-extra mcp-tasks pytest src/pydantic_ai_harness/integration_tests/redis
.PHONY: update-examples
update-examples: ## Update documentation examples
uv run -m pytest --update-examples tests/test_examples.py
.PHONY: update-vcr-tests
update-vcr-tests: ## Update tests using VCR that hit LLM APIs; note you'll need to set API keys as appropriate
uv run -m pytest --record-mode=rewrite tests
.PHONY: all
all: format lint typecheck testcov ## Run code formatting, linting, static type checks, and tests with coverage report generation
.PHONY: help
help: ## Show this help (usage: make help)
@echo "Usage: make [recipe]"
@echo "Recipes:"
@awk '/^[a-zA-Z0-9_-]+:.*?##/ { \
helpMessage = match($$0, /## (.*)/); \
if (helpMessage) { \
recipe = $$1; \
sub(/:/, "", recipe); \
printf " \033[36m%-20s\033[0m %s\n", recipe, substr($$0, RSTART + 3, RLENGTH); \
} \
}' $(MAKEFILE_LIST)