|
| 1 | +SHELL := /bin/bash |
| 2 | + |
| 3 | +# ============================================================================= |
| 4 | +# Configuration and Environment Variables |
| 5 | +# ============================================================================= |
| 6 | + |
1 | 7 | .DEFAULT_GOAL:=help |
2 | 8 | .ONESHELL: |
3 | | -ENV_PREFIX =.venv/bin/ |
4 | | -VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')") |
5 | | -BUILD_DIR =dist |
6 | | -SRC_DIR =src |
7 | | -BASE_DIR =$(shell pwd) |
8 | | - |
9 | 9 | .EXPORT_ALL_VARIABLES: |
| 10 | +MAKEFLAGS += --no-print-directory |
| 11 | + |
| 12 | +# ----------------------------------------------------------------------------- |
| 13 | +# Display Formatting and Colors |
| 14 | +# ----------------------------------------------------------------------------- |
| 15 | +BLUE := $(shell printf "\033[1;34m") |
| 16 | +GREEN := $(shell printf "\033[1;32m") |
| 17 | +RED := $(shell printf "\033[1;31m") |
| 18 | +YELLOW := $(shell printf "\033[1;33m") |
| 19 | +NC := $(shell printf "\033[0m") |
| 20 | +INFO := $(shell printf "$(BLUE)ℹ$(NC)") |
| 21 | +OK := $(shell printf "$(GREEN)✓$(NC)") |
| 22 | +WARN := $(shell printf "$(YELLOW)⚠$(NC)") |
| 23 | +ERROR := $(shell printf "$(RED)✖$(NC)") |
10 | 24 |
|
11 | | -ifndef VERBOSE |
12 | | -.SILENT: |
13 | | -endif |
14 | | - |
| 25 | +# ============================================================================= |
| 26 | +# Help and Documentation |
| 27 | +# ============================================================================= |
15 | 28 |
|
16 | | -help: ## Display this help |
| 29 | +.PHONY: help |
| 30 | +help: ## Display this help text for Makefile |
17 | 31 | @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) |
18 | 32 |
|
19 | | - |
20 | 33 | # ============================================================================= |
21 | | -# Developer Utils |
| 34 | +# Installation and Environment Setup |
22 | 35 | # ============================================================================= |
23 | | -install-hatch: ## Install Hatch |
24 | | - @sh ./scripts/install-hatch.sh |
25 | 36 |
|
26 | | -configure-hatch: ## Configure Hatch defaults |
27 | | - @hatch config set dirs.env.virtual .direnv |
28 | | - @hatch config set dirs.env.pip-compile .direnv |
| 37 | +.PHONY: install-uv |
| 38 | +install-uv: ## Install latest version of uv |
| 39 | + @echo "${INFO} Installing uv..." |
| 40 | + @curl -LsSf https://astral.sh/uv/install.sh | sh >/dev/null 2>&1 |
| 41 | + @uv tool install nodeenv >/dev/null 2>&1 |
| 42 | + @echo "${OK} UV installed successfully" |
| 43 | + |
| 44 | +.PHONY: install |
| 45 | +install: destroy clean ## Install the project, dependencies, and pre-commit |
| 46 | + @echo "${INFO} Starting fresh installation..." |
| 47 | + @uv python pin 3.12 >/dev/null 2>&1 |
| 48 | + @uv venv >/dev/null 2>&1 |
| 49 | + @uv sync --all-extras --dev |
| 50 | + @echo "${OK} Installation complete! 🎉" |
| 51 | + |
| 52 | +.PHONY: destroy |
| 53 | +destroy: ## Destroy the virtual environment |
| 54 | + @echo "${INFO} Destroying virtual environment... 🗑️" |
| 55 | + @rm -rf .venv |
| 56 | + @echo "${OK} Virtual environment destroyed 🗑️" |
29 | 57 |
|
30 | | -upgrade-hatch: ## Update Hatch, UV, and Ruff |
31 | | - @hatch self update |
| 58 | +# ============================================================================= |
| 59 | +# Dependency Management |
| 60 | +# ============================================================================= |
32 | 61 |
|
33 | | -install: ## Install the project and all dependencies |
34 | | - @if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; $(MAKE) destroy-venv; fi |
35 | | - @$(MAKE) clean |
36 | | - @if ! hatch --version > /dev/null; then echo '=> Installing `hatch` with standalone installation'; $(MAKE) install-hatch ; fi |
37 | | - @if ! hatch-pip-compile --version > /dev/null; then echo '=> Updating `hatch` and installing plugins'; $(MAKE) upgrade-hatch ; fi |
38 | | - @echo "=> Creating Python environments..." |
39 | | - @$(MAKE) configure-hatch |
40 | | - @hatch env create local |
41 | | - @echo "=> Install complete! Note: If you want to re-install re-run 'make install'" |
| 62 | +.PHONY: upgrade |
| 63 | +upgrade: ## Upgrade all dependencies to latest stable versions |
| 64 | + @echo "${INFO} Updating all dependencies... 🔄" |
| 65 | + @uv lock --upgrade |
| 66 | + @echo "${OK} Dependencies updated 🔄" |
| 67 | + @uv run pre-commit autoupdate |
| 68 | + @echo "${OK} Updated Pre-commit hooks 🔄" |
| 69 | + |
| 70 | +.PHONY: lock |
| 71 | +lock: ## Rebuild lockfiles from scratch |
| 72 | + @echo "${INFO} Rebuilding lockfiles... 🔄" |
| 73 | + @uv lock --upgrade >/dev/null 2>&1 |
| 74 | + @echo "${OK} Lockfiles updated" |
42 | 75 |
|
| 76 | +# ============================================================================= |
| 77 | +# Build and Release |
| 78 | +# ============================================================================= |
43 | 79 |
|
44 | | -.PHONY: upgrade |
45 | | -upgrade: ## Upgrade all dependencies to the latest stable versions |
46 | | - @echo "=> Updating all dependencies" |
47 | | - @hatch-pip-compile --upgrade --all |
48 | | - @echo "=> Python Dependencies Updated" |
49 | | - @hatch run lint:pre-commit autoupdate |
50 | | - @echo "=> Updated Pre-commit" |
| 80 | +.PHONY: build |
| 81 | +build: ## Build the package |
| 82 | + @echo "${INFO} Building package... 📦" |
| 83 | + @uv build >/dev/null 2>&1 |
| 84 | + @echo "${OK} Package build complete" |
| 85 | + |
| 86 | +.PHONY: release |
| 87 | +release: ## Bump version and create release tag |
| 88 | + @echo "${INFO} Preparing for release... 📦" |
| 89 | + @make docs |
| 90 | + @make clean |
| 91 | + @make build |
| 92 | + @uv lock --upgrade-package pytest-databases |
| 93 | + @uv run bump-my-version bump $(bump) |
| 94 | + @echo "${OK} Release complete 🎉" |
51 | 95 |
|
| 96 | +# ============================================================================= |
| 97 | +# Cleaning and Maintenance |
| 98 | +# ============================================================================= |
52 | 99 |
|
53 | 100 | .PHONY: clean |
54 | | -clean: ## remove all build, testing, and static documentation files |
55 | | - @echo "=> Cleaning working directory" |
56 | | - @rm -rf .pytest_cache .ruff_cache .hypothesis build/ dist/ .eggs/ .coverage coverage.xml coverage.json htmlcov/ .mypy_cache |
57 | | - @find . -name '*.egg-info' -exec rm -rf {} + |
58 | | - @find . -name '*.egg' -exec rm -f {} + |
59 | | - @find . -name '*.pyc' -exec rm -f {} + |
60 | | - @find . -name '*.pyo' -exec rm -f {} + |
61 | | - @find . -name '*~' -exec rm -f {} + |
62 | | - @find . -name '__pycache__' -exec rm -rf {} + |
63 | | - @find . -name '.pytest_cache' -exec rm -rf {} + |
64 | | - @find . -name '.ipynb_checkpoints' -exec rm -rf {} + |
65 | | - @echo "=> Source cleaned successfully" |
66 | | - |
67 | | -deep-clean: clean destroy-venv ## Clean everything up |
68 | | - @hatch python remove all |
69 | | - @echo "=> Hatch environments pruned and python installations trimmed" |
70 | | - @uv cache clean |
71 | | - @echo "=> UV Cache cleaned successfully" |
72 | | - |
73 | | -destroy-venv: ## Destroy the virtual environment |
74 | | - @hatch env prune |
75 | | - @hatch env remove lint |
76 | | - @rm -Rf .venv |
77 | | - @rm -Rf .direnv |
78 | | - |
79 | | -.PHONY: build |
80 | | -build: clean ## Build and package the collectors |
81 | | - @echo "=> Building package..." |
82 | | - @hatch build |
83 | | - @echo "=> Package build complete..." |
| 101 | +clean: ## Cleanup temporary build artifacts |
| 102 | + @echo "${INFO} Cleaning working directory... 🧹" |
| 103 | + @rm -rf .pytest_cache .ruff_cache .hypothesis build/ dist/ .eggs/ .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache .unasyncd_cache/ .auto_pytabs_cache node_modules >/dev/null 2>&1 |
| 104 | + @find . -name '*.egg-info' -exec rm -rf {} + >/dev/null 2>&1 |
| 105 | + @find . -type f -name '*.egg' -exec rm -f {} + >/dev/null 2>&1 |
| 106 | + @find . -name '*.pyc' -exec rm -f {} + >/dev/null 2>&1 |
| 107 | + @find . -name '*.pyo' -exec rm -f {} + >/dev/null 2>&1 |
| 108 | + @find . -name '*~' -exec rm -f {} + >/dev/null 2>&1 |
| 109 | + @find . -name '__pycache__' -exec rm -rf {} + >/dev/null 2>&1 |
| 110 | + @find . -name '.ipynb_checkpoints' -exec rm -rf {} + >/dev/null 2>&1 |
| 111 | + @echo "${OK} Working directory cleaned" |
| 112 | + $(MAKE) docs-clean |
84 | 113 |
|
| 114 | +# ============================================================================= |
| 115 | +# Testing and Quality Checks |
| 116 | +# ============================================================================= |
85 | 117 |
|
86 | | -############### |
87 | | -# docs # |
88 | | -############### |
89 | | -.PHONY: serve-docs |
90 | | -serve-docs: ## Serve HTML documentation |
91 | | - @hatch run docs:serve |
| 118 | +.PHONY: test |
| 119 | +test: ## Run the tests |
| 120 | + @echo "${INFO} Running test cases... 🧪" |
| 121 | + @uv run pytest -n 2 --quiet |
| 122 | + @echo "${OK} Tests passed ✨" |
| 123 | + |
| 124 | +.PHONY: coverage |
| 125 | +coverage: ## Run tests with coverage report |
| 126 | + @echo "${INFO} Running tests with coverage... 📊" |
| 127 | + @uv run pytest --cov -n auto --quiet |
| 128 | + @uv run coverage html >/dev/null 2>&1 |
| 129 | + @uv run coverage xml >/dev/null 2>&1 |
| 130 | + @echo "${OK} Coverage report generated ✨" |
| 131 | + |
| 132 | +# ----------------------------------------------------------------------------- |
| 133 | +# Type Checking |
| 134 | +# ----------------------------------------------------------------------------- |
| 135 | + |
| 136 | +.PHONY: mypy |
| 137 | +mypy: ## Run mypy |
| 138 | + @echo "${INFO} Running mypy... 🔍" |
| 139 | + @uv run dmypy run |
| 140 | + @echo "${OK} Mypy checks passed ✨" |
| 141 | + |
| 142 | +.PHONY: mypy-nocache |
| 143 | +mypy-nocache: ## Run Mypy without cache |
| 144 | + @echo "${INFO} Running mypy without cache... 🔍" |
| 145 | + @uv run mypy |
| 146 | + @echo "${OK} Mypy checks passed ✨" |
| 147 | + |
| 148 | +.PHONY: pyright |
| 149 | +pyright: ## Run pyright |
| 150 | + @echo "${INFO} Running pyright... 🔍" |
| 151 | + @uv run pyright |
| 152 | + @echo "${OK} Pyright checks passed ✨" |
| 153 | + |
| 154 | +.PHONY: type-check |
| 155 | +type-check: mypy pyright ## Run all type checking |
| 156 | + |
| 157 | +# ----------------------------------------------------------------------------- |
| 158 | +# Linting and Formatting |
| 159 | +# ----------------------------------------------------------------------------- |
| 160 | + |
| 161 | +.PHONY: pre-commit |
| 162 | +pre-commit: ## Run pre-commit hooks |
| 163 | + @echo "${INFO} Running pre-commit checks... 🔎" |
| 164 | + @NODE_OPTIONS="--no-deprecation --disable-warning=ExperimentalWarning" uv run pre-commit run --color=always --all-files |
| 165 | + @echo "${OK} Pre-commit checks passed ✨" |
| 166 | + |
| 167 | +.PHONY: slotscheck |
| 168 | +slotscheck: ## Run slotscheck |
| 169 | + @echo "${INFO} Running slots check... 🔍" |
| 170 | + @uv run slotscheck |
| 171 | + @echo "${OK} Slots check passed ✨" |
| 172 | + |
| 173 | +.PHONY: fix |
| 174 | +fix: ## Run code formatters |
| 175 | + @echo "${INFO} Running code formatters... 🔧" |
| 176 | + @uv run ruff check --fix --unsafe-fixes |
| 177 | + @echo "${OK} Code formatting complete ✨" |
92 | 178 |
|
93 | | -.PHONY: docs |
94 | | -docs: ## generate HTML documentation and serve it to the browser |
95 | | - @hatch run docs:build |
| 179 | +.PHONY: lint |
| 180 | +lint: pre-commit type-check slotscheck ## Run all linting checks |
96 | 181 |
|
| 182 | +.PHONY: check-all |
| 183 | +check-all: lint test coverage ## Run all checks (lint, test, coverage) |
97 | 184 |
|
98 | 185 | # ============================================================================= |
99 | | -# Tests, Linting, Coverage |
| 186 | +# Documentation |
100 | 187 | # ============================================================================= |
101 | | -.PHONY: lint |
102 | | -lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black |
103 | | - @echo "=> Running pre-commit process" |
104 | | - @hatch run lint:fix |
105 | | - @echo "=> Pre-commit complete" |
106 | 188 |
|
107 | | -.PHONY: test |
108 | | -test: ## Run the tests |
109 | | - @echo "=> Running test cases" |
110 | | - @hatch run +py=3.12 test:cov |
111 | | - @echo "=> Tests complete" |
112 | | - |
113 | | -.PHONY: test-all |
114 | | -test-all: ## Run the tests for all python versions |
115 | | - @echo "=> Running test cases" |
116 | | - @hatch run test:cov |
117 | | - @echo "=> Tests complete" |
| 189 | +.PHONY: docs-clean |
| 190 | +docs-clean: ## Clean documentation build |
| 191 | + @echo "${INFO} Cleaning documentation build assets... 🧹" |
| 192 | + @rm -rf docs/_build >/dev/null 2>&1 |
| 193 | + @echo "${OK} Documentation assets cleaned" |
| 194 | + |
| 195 | +.PHONY: docs-serve |
| 196 | +docs-serve: ## Serve documentation locally |
| 197 | + @echo "${INFO} Starting documentation server... 📚" |
| 198 | + @uv run sphinx-autobuild docs docs/_build/ -j auto --watch src/pytest_databases --watch docs --watch tests --watch CONTRIBUTING.rst --open-browser |
| 199 | + |
| 200 | +.PHONY: docs |
| 201 | +docs: docs-clean ## Build documentation |
| 202 | + @echo "${INFO} Building documentation... 📝" |
| 203 | + @uv run sphinx-build -M html docs docs/_build/ -E -a -j auto -W --keep-going |
| 204 | + @echo "${OK} Documentation built successfully" |
| 205 | + |
| 206 | +.PHONY: docs-linkcheck |
| 207 | +docs-linkcheck: ## Check documentation links |
| 208 | + @echo "${INFO} Checking documentation links... 🔗" |
| 209 | + @uv run sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_ignore='http://.*','https://.*' |
| 210 | + @echo "${OK} Link check complete" |
| 211 | + |
| 212 | +.PHONY: docs-linkcheck-full |
| 213 | +docs-linkcheck-full: ## Run full documentation link check |
| 214 | + @echo "${INFO} Running full link check... 🔗" |
| 215 | + @uv run sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_anchors=0 |
| 216 | + @echo "${OK} Full link check complete" |
0 commit comments