| 1 |
SHELL := /bin/bash |
| 2 |
# ============================================================================= |
| 3 |
# Variables |
| 4 |
# ============================================================================= |
| 5 |
|
| 6 |
.DEFAULT_GOAL:=help |
| 7 |
.ONESHELL: |
| 8 |
ENV_PREFIX = .venv/bin/ |
| 9 |
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')") |
| 10 |
|
| 11 |
.EXPORT_ALL_VARIABLES: |
| 12 |
|
| 13 |
|
| 14 |
.PHONY: help |
| 15 |
help: ## Display this help text for Makefile |
| 16 |
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 17 |
|
| 18 |
.PHONY: upgrade |
| 19 |
upgrade: ## Upgrade all dependencies to the latest stable versions |
| 20 |
@echo "=> Updating all dependencies" |
| 21 |
@uv lock --upgrade |
| 22 |
@echo "=> Dependencies Updated" |
| 23 |
@uv run pre-commit autoupdate |
| 24 |
@echo "=> Updated Pre-commit" |
| 25 |
|
| 26 |
# ============================================================================= |
| 27 |
# Developer Utils |
| 28 |
# ============================================================================= |
| 29 |
|
| 30 |
.PHONY: install |
| 31 |
install: ## Install dependencies |
| 32 |
@uv sync |
| 33 |
|
| 34 |
.PHONY: clean |
| 35 |
clean: ## Cleanup temporary build artifacts |
| 36 |
@echo "=> Cleaning working directory" |
| 37 |
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/ |
| 38 |
@find . -name '*.egg-info' -exec rm -rf {} + |
| 39 |
@find . -type f -name '*.egg' -exec rm -f {} + |
| 40 |
@find . -name '*.pyc' -exec rm -f {} + |
| 41 |
@find . -name '*.pyo' -exec rm -f {} + |
| 42 |
@find . -name '*~' -exec rm -f {} + |
| 43 |
@find . -name '__pycache__' -exec rm -rf {} + |
| 44 |
@find . -name '.ipynb_checkpoints' -exec rm -rf {} + |
| 45 |
@rm -rf .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache |
| 46 |
$(MAKE) docs-clean |
| 47 |
|
| 48 |
.PHONY: destroy |
| 49 |
destroy: ## Destroy the virtual environment |
| 50 |
@rm -rf .venv |
| 51 |
|
| 52 |
|
| 53 |
.PHONY: lock |
| 54 |
lock: ## Rebuild lockfiles from scratch, updating all dependencies |
| 55 |
@uv lock |
| 56 |
|
| 57 |
# ============================================================================= |
| 58 |
# Tests, Linting, Coverage |
| 59 |
# ============================================================================= |
| 60 |
.PHONY: mypy |
| 61 |
mypy: ## Run mypy |
| 62 |
@echo "=> Running mypy" |
| 63 |
@uv run dmypy run |
| 64 |
@echo "=> mypy complete" |
| 65 |
|
| 66 |
.PHONY: mypy-nocache |
| 67 |
mypy-nocache: ## Run Mypy without cache |
| 68 |
@echo "=> Running mypy without a cache" |
| 69 |
@uv run dmypy run -- --cache-dir=/dev/null |
| 70 |
@echo "=> mypy complete" |
| 71 |
|
| 72 |
.PHONY: pyright |
| 73 |
pyright: ## Run pyright |
| 74 |
@echo "=> Running pyright" |
| 75 |
@uv run pyright |
| 76 |
@echo "=> pyright complete" |
| 77 |
|
| 78 |
.PHONY: type-check |
| 79 |
type-check: mypy pyright ## Run all type checking |
| 80 |
|
| 81 |
.PHONY: pre-commit |
| 82 |
pre-commit: ## Runs pre-commit hooks; includes ruff formatting and linting, codespell |
| 83 |
@echo "=> Running pre-commit process" |
| 84 |
@uv run pre-commit run --all-files |
| 85 |
@echo "=> Pre-commit complete" |
| 86 |
|
| 87 |
.PHONY: slots-check |
| 88 |
slots-check: ## Check for slots usage in classes |
| 89 |
@echo "=> Checking for slots usage in classes" |
| 90 |
@uv run slotscheck litestar |
| 91 |
@echo "=> Slots check complete" |
| 92 |
|
| 93 |
.PHONY: lint |
| 94 |
lint: pre-commit type-check slots-check ## Run all linting |
| 95 |
|
| 96 |
.PHONY: coverage |
| 97 |
coverage: ## Run the tests and generate coverage report |
| 98 |
@echo "=> Running tests with coverage" |
| 99 |
@uv run pytest tests --cov -n auto |
| 100 |
@uv run coverage html |
| 101 |
@uv run coverage xml |
| 102 |
@echo "=> Coverage report generated" |
| 103 |
|
| 104 |
.PHONY: test |
| 105 |
test: ## Run the tests |
| 106 |
@echo "=> Running test cases" |
| 107 |
@uv run pytest tests |
| 108 |
@echo "=> Tests complete" |
| 109 |
|
| 110 |
.PHONY: test-examples |
| 111 |
test-examples: ## Run the examples tests |
| 112 |
@uv run pytest docs/examples |
| 113 |
|
| 114 |
.PHONY: test-all |
| 115 |
test-all: test test-examples ## Run all tests |
| 116 |
|
| 117 |
.PHONY: check-all |
| 118 |
check-all: lint test-all coverage ## Run all linting, tests, and coverage checks |
| 119 |
|
| 120 |
|
| 121 |
# ============================================================================= |
| 122 |
# Docs |
| 123 |
# ============================================================================= |
| 124 |
# XXX: docs commands are pinned to Python 3.12 due to picologging not being compatible with 3.13 |
| 125 |
|
| 126 |
.PHONY: docs-install |
| 127 |
docs-install: ## Install docs dependencies |
| 128 |
@echo "=> Installing documentation dependencies" |
| 129 |
@uv sync --python 3.12 --group docs |
| 130 |
@echo "=> Installed documentation dependencies" |
| 131 |
|
| 132 |
docs-clean: ## Dump the existing built docs |
| 133 |
@echo "=> Cleaning documentation build assets" |
| 134 |
@rm -rf docs/_build |
| 135 |
@echo "=> Removed existing documentation build assets" |
| 136 |
|
| 137 |
docs-serve: docs-clean ## Serve the docs locally |
| 138 |
@echo "=> Serving documentation" |
| 139 |
uv run --python 3.12 sphinx-autobuild docs docs/_build/ -j auto --watch litestar --watch docs --watch tests --watch CONTRIBUTING.rst --open-browser --port=0 |
| 140 |
|
| 141 |
docs: docs-clean ## Dump the existing built docs and rebuild them |
| 142 |
@echo "=> Building documentation" |
| 143 |
@uv run --python 3.12 sphinx-build -M html docs docs/_build/ -E -a -j auto -W --keep-going |
| 144 |
|
| 145 |
.PHONY: docs-linkcheck |
| 146 |
docs-linkcheck: ## Run the link check on the docs |
| 147 |
@uv run --python 3.12 sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_ignore='http://.*','https://.*' |
| 148 |
|
| 149 |
.PHONY: docs-linkcheck-full |
| 150 |
docs-linkcheck-full: ## Run the full link check on the docs |
| 151 |
@uv run --python 3.12 sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_anchors=0 |