-
Notifications
You must be signed in to change notification settings - Fork 168
/
Makefile
127 lines (102 loc) · 3.86 KB
/
Makefile
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
SHELL := /bin/bash
.DEFAULT_GOAL := help
pkg_src = fastapi_utils
tests_src = tests
docs_src = docs/src
all_src = $(pkg_src) $(tests_src)
mypy_base = mypy --show-error-codes
mypy = $(mypy_base) $(all_src)
test = pytest --cov=$(pkg_src)
.PHONY: all ## Run the most common rules used during development
all: static test
.PHONY: static ## Perform all static checks (format, mypy)
static: format lint mypy
.PHONY: test ## Run tests
test:
$(test)
.PHONY: format ## Auto-format the source code (ruff, black)
format:
black $(all_src)
black -l 82 $(docs_src)
ruff check --fix $(all_src)
.PHONY: lint
lint:
ruff check $(all_src)
black --check --diff $(all_src)
black -l 82 $(docs_src) --check --diff
.PHONY: mypy ## Run mypy over the application source and tests
mypy:
$(mypy)
.PHONY: testcov ## Run tests, generate a coverage report, and open in browser
testcov:
$(test)
@echo "building coverage html"
@coverage html
@echo "A coverage report was generated at htmlcov/index.html"
@if [ "$$(uname -s)" = "Darwin" ]; then \
open htmlcov/index.html; \
fi
.PHONY: ci-v1 ## Run all CI validation steps without making any changes to code in pydantic v1
ci-v1: install-v1 lint test
.PHONY: ci-v2 ## Run all CI validation steps without making any changes to code in pydantic v2
ci-v2: install-v2 lint mypy test
install-v1:
poetry run python -m pip uninstall "pydantic-settings" -y
poetry run python -m pip uninstall "typing-inspect" -y
poetry run python -m pip install "pydantic>=1.10,<2.0.0"
install-v2:
poetry run python -m pip install "pydantic>=2.0.0,<3.0.0"
poetry run python -m pip install "pydantic-settings>=2.0.0,<3.0.0"
poetry run python -m pip install "typing-inspect>=0.9.0,<1.0.0"
.PHONY: clean ## Remove temporary and cache files/directories
clean:
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -f `find . -type f -name .coverage`
rm -f `find . -type f -name ".coverage.*"`
rm -rf `find . -name __pycache__`
rm -rf `find . -type d -name '*.egg-info' `
rm -rf `find . -type d -name 'pip-wheel-metadata' `
rm -rf `find . -type d -name .pytest_cache`
rm -rf `find . -type d -name .cache`
rm -rf `find . -type d -name .mypy_cache`
rm -rf `find . -type d -name .ruff_cache`
rm -rf `find . -type d -name htmlcov`
rm -rf `find . -type d -name "*.egg-info"`
rm -rf `find . -type d -name build`
rm -rf `find . -type d -name dist`
.PHONY: lock ## Update the lockfile
lock:
./scripts/lock.sh
.PHONY: develop ## Set up the development environment, or reinstall from the lockfile
develop:
./scripts/develop.sh
.PHONY: version ## Bump the version in both pyproject.toml and __init__.py (usage: `make version version=minor`)
version: poetryversion
$(eval NEW_VERS := $(shell cat pyproject.toml | grep "^version = \"*\"" | cut -d'"' -f2))
@sed -i "s/__version__ = .*/__version__ = \"$(NEW_VERS)\"/g" $(pkg_src)/__init__.py
.PHONY: docs-build ## Generate the docs and update README.md
docs-build:
cp ./README.md ./docs/index.md
cp ./CONTRIBUTING.md ./docs/contributing.md
cp ./CHANGELOG.md ./docs/release-notes.md
pip install mkdocs mkdocs-material markdown-include
python -m mkdocs build
.PHONY: docs-format ## Format the python code that is part of the docs
docs-format:
ruff check $(docs_src)
autoflake -r --remove-all-unused-imports --ignore-init-module-imports $(docs_src) -i
black -l 82 $(docs_src)
.PHONY: docs-live ## Serve the docs with live reload as you make changes
docs-live:
mkdocs serve --dev-addr 0.0.0.0:8008
.PHONY: poetryversion
poetryversion:
poetry version $(version)
.PHONY: help ## Display this message
help:
@grep -E \
'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-16s\033[0m %s\n", $$2, $$3}'