-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathMakefile
More file actions
166 lines (141 loc) · 6.49 KB
/
Makefile
File metadata and controls
166 lines (141 loc) · 6.49 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
.DEFAULT_GOAL := all
# Detect OS
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
else
DETECTED_OS := $(shell uname -s)
endif
.PHONY: .uv
.uv: ## Check that uv is installed
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'
.PHONY: .pre-commit
.pre-commit: ## Check that pre-commit is installed
@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'
.PHONY: install
install: .uv .pre-commit ## Install the package, dependencies, and pre-commit for local development
uv sync --frozen --all-extras --all-packages --group lint --group docs
pre-commit install --install-hooks
.PHONY: install-all-python
install-all-python: ## Install and synchronize an interpreter for every python version
ifeq ($(DETECTED_OS),Windows)
@set UV_PROJECT_ENVIRONMENT=.venv310 & uv sync --python 3.10 --frozen --all-extras --all-packages --group lint --group docs
@set UV_PROJECT_ENVIRONMENT=.venv311 & uv sync --python 3.11 --frozen --all-extras --all-packages --group lint --group docs
@set UV_PROJECT_ENVIRONMENT=.venv312 & uv sync --python 3.12 --frozen --all-extras --all-packages --group lint --group docs
@set UV_PROJECT_ENVIRONMENT=.venv313 & uv sync --python 3.13 --frozen --all-extras --all-packages --group lint --group docs
else
UV_PROJECT_ENVIRONMENT=.venv310 uv sync --python 3.10 --frozen --all-extras --all-packages --group lint --group docs
UV_PROJECT_ENVIRONMENT=.venv311 uv sync --python 3.11 --frozen --all-extras --all-packages --group lint --group docs
UV_PROJECT_ENVIRONMENT=.venv312 uv sync --python 3.12 --frozen --all-extras --all-packages --group lint --group docs
UV_PROJECT_ENVIRONMENT=.venv313 uv sync --python 3.13 --frozen --all-extras --all-packages --group lint --group docs
endif
.PHONY: sync
sync: .uv ## Update local packages and uv.lock
uv sync --all-extras --all-packages --group lint --group docs
.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
.PHONY: typecheck-pyright
typecheck-pyright:
ifeq ($(DETECTED_OS),Windows)
@set PYRIGHT_PYTHON_IGNORE_WARNINGS=1 & uv run pyright
else
@# PYRIGHT_PYTHON_IGNORE_WARNINGS avoids the overhead of making a request to github on every invocation
PYRIGHT_PYTHON_IGNORE_WARNINGS=1 uv run pyright
endif
.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 and collect coverage data
uv run coverage run -m pytest -n auto --dist=loadgroup --durations=20
@uv run coverage combine
@uv run coverage report
.PHONY: test-all-python
test-all-python: ## Run tests on Python 3.10 to 3.13
ifeq ($(DETECTED_OS),Windows)
@set UV_PROJECT_ENVIRONMENT=.venv310 & uv run --python 3.10 --all-extras --all-packages coverage run -p -m pytest
@set UV_PROJECT_ENVIRONMENT=.venv311 & uv run --python 3.11 --all-extras --all-packages coverage run -p -m pytest
@set UV_PROJECT_ENVIRONMENT=.venv312 & uv run --python 3.12 --all-extras --all-packages coverage run -p -m pytest
@set UV_PROJECT_ENVIRONMENT=.venv313 & uv run --python 3.13 --all-extras --all-packages coverage run -p -m pytest
else
UV_PROJECT_ENVIRONMENT=.venv310 uv run --python 3.10 --all-extras --all-packages coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv311 uv run --python 3.11 --all-extras --all-packages coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv312 uv run --python 3.12 --all-extras --all-packages coverage run -p -m pytest
UV_PROJECT_ENVIRONMENT=.venv313 uv run --python 3.13 --all-extras --all-packages coverage run -p -m pytest
endif
@uv run coverage combine
@uv run coverage report
.PHONY: testcov
testcov: test ## Run tests and generate an HTML coverage report
@echo "building coverage html"
@uv run coverage html
.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
# `--no-strict` so you can build the docs without insiders packages
.PHONY: docs
docs: ## Build the documentation
uv run mkdocs build --no-strict
# `--no-strict` so you can build the docs without insiders packages
.PHONY: docs-serve
docs-serve: ## Build and serve the documentation
uv run mkdocs serve --no-strict
.PHONY: .docs-insiders-install
.docs-insiders-install: ## Install insiders packages for docs if necessary
ifeq ($(PPPR_TOKEN),)
@echo Error: PPPR_TOKEN is not set, cannot install insiders packages
@exit 1
else
@echo installing insiders packages...
@uv pip install --reinstall --no-deps \
--extra-index-url https://pydantic:${PPPR_TOKEN}@pppr.pydantic.dev/simple/ \
mkdocs-material mkdocstrings-python
endif
.PHONY: docs-insiders
docs-insiders: .docs-insiders-install ## Build the documentation using insiders packages
uv run --no-sync mkdocs build -f mkdocs.insiders.yml
.PHONY: docs-serve-insiders
docs-serve-insiders: .docs-insiders-install ## Build and serve the documentation using insiders packages
uv run --no-sync mkdocs serve -f mkdocs.insiders.yml
.PHONY: cf-pages-build
cf-pages-build: ## Install uv, install dependencies and build the docs, used on CloudFlare Pages
curl -LsSf https://astral.sh/uv/install.sh | sh
uv python install 3.12
uv sync --python 3.12 --frozen --group docs
uv pip install --reinstall --no-deps \
--extra-index-url https://pydantic:${PPPR_TOKEN}@pppr.pydantic.dev/simple/ \
mkdocs-material mkdocstrings-python
uv pip freeze
uv run --no-sync mkdocs build -f mkdocs.insiders.yml
.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)
ifeq ($(DETECTED_OS),Windows)
@echo Usage: make [recipe]
@echo Recipes:
@uv run python -c "import re; [print(f' {m[0]:<20} {m[1]}') for m in re.findall(r'^([a-zA-Z0-9_-]+):.*?## (.*)$$', open('$(MAKEFILE_LIST)').read(), re.MULTILINE)]"
else
@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)
endif