|
| 1 | +PYTHON ?= $(if $(wildcard .venv/bin/python),.venv/bin/python,$(shell if command -v python3.12 >/dev/null 2>&1; then echo python3.12; else echo python3; fi)) |
| 2 | +PIP ?= $(PYTHON) -m pip |
| 3 | +PYTEST ?= $(PYTHON) -m pytest |
| 4 | +RUFF ?= $(PYTHON) -m ruff |
| 5 | +MYPY ?= $(PYTHON) -m mypy |
| 6 | +SPHINX ?= $(PYTHON) -m sphinx |
| 7 | +BUILD ?= $(PYTHON) -m build |
| 8 | +TWINE ?= $(PYTHON) -m twine |
| 9 | +UV ?= $(if $(wildcard .venv/bin/uv),.venv/bin/uv,uv) |
| 10 | +REPRO_PYTHON ?= $(shell cat .python-version 2>/dev/null || echo 3.12.12) |
| 11 | +REPRO_EXTRAS ?= dev |
| 12 | + |
| 13 | +.PHONY: help check-python check-uv dev install-dev repro lock \ |
| 14 | + lint fmt fmt-check type test qa coverage docstrings-check \ |
| 15 | + run-example docs docs-build docs-check docs-linkcheck \ |
| 16 | + release-check ci clean |
| 17 | + |
| 18 | +help: |
| 19 | + @echo "Common targets:" |
| 20 | + @echo " dev Install the project in editable mode with dev dependencies." |
| 21 | + @echo " repro Frozen reproducible install using uv.lock." |
| 22 | + @echo " lock Regenerate uv.lock." |
| 23 | + @echo " test Run the pytest suite." |
| 24 | + @echo " qa Run lint, fmt-check, type, and test." |
| 25 | + @echo " run-example Execute the bundled example script." |
| 26 | + @echo " docs Build the HTML docs." |
| 27 | + @echo " ci Run the main local CI checks." |
| 28 | + |
| 29 | +check-python: |
| 30 | + @$(PYTHON) -c "import pathlib, sys; print(f'Using Python {sys.version.split()[0]} at {pathlib.Path(sys.executable)}'); raise SystemExit(0 if sys.version_info >= (3, 12) else 1)" || (echo "Python >= 3.12 is required by pyproject.toml"; exit 1) |
| 31 | + |
| 32 | +check-uv: |
| 33 | + @command -v $(UV) >/dev/null 2>&1 || (echo "uv is required for lock/repro targets. Install it from https://docs.astral.sh/uv/getting-started/installation/"; exit 1) |
| 34 | + |
| 35 | +dev: |
| 36 | + $(PIP) install --upgrade pip setuptools wheel |
| 37 | + $(PIP) install -e ".[dev]" |
| 38 | + |
| 39 | +install-dev: dev |
| 40 | + |
| 41 | +repro: check-uv |
| 42 | + $(UV) sync --frozen --python $(REPRO_PYTHON) $(foreach extra,$(REPRO_EXTRAS),--extra $(extra)) |
| 43 | + |
| 44 | +lock: check-uv |
| 45 | + $(UV) lock --python $(REPRO_PYTHON) |
| 46 | + |
| 47 | +lint: check-python |
| 48 | + $(RUFF) check . |
| 49 | + |
| 50 | +fmt: check-python |
| 51 | + $(RUFF) format . |
| 52 | + |
| 53 | +fmt-check: check-python |
| 54 | + $(RUFF) format --check . |
| 55 | + |
| 56 | +type: check-python |
| 57 | + $(MYPY) src |
| 58 | + |
| 59 | +test: check-python |
| 60 | + PYTHONPATH=src $(PYTEST) -q |
| 61 | + |
| 62 | +qa: lint fmt-check type test |
| 63 | + |
| 64 | +coverage: check-python |
| 65 | + mkdir -p artifacts/coverage |
| 66 | + PYTHONPATH=src $(PYTEST) --cov=src/design_research_python_template --cov-report=term --cov-report=json:artifacts/coverage/coverage.json -q |
| 67 | + $(PYTHON) scripts/check_coverage_thresholds.py --coverage-json artifacts/coverage/coverage.json |
| 68 | + |
| 69 | +docstrings-check: check-python |
| 70 | + $(PYTHON) scripts/check_google_docstrings.py |
| 71 | + |
| 72 | +run-example: check-python |
| 73 | + PYTHONPATH=src $(PYTHON) examples/basic_usage.py |
| 74 | + |
| 75 | +docs-build: check-python |
| 76 | + PYTHONPATH=src $(SPHINX) -b html docs docs/_build/html -n -W --keep-going -E |
| 77 | + |
| 78 | +docs-check: check-python |
| 79 | + $(PYTHON) scripts/check_docs_consistency.py |
| 80 | + |
| 81 | +docs-linkcheck: check-python |
| 82 | + PYTHONPATH=src $(SPHINX) -b linkcheck docs docs/_build/linkcheck -W --keep-going -E |
| 83 | + |
| 84 | +docs: docs-build |
| 85 | + |
| 86 | +release-check: check-python |
| 87 | + rm -rf build dist |
| 88 | + $(BUILD) --no-isolation |
| 89 | + $(TWINE) check dist/* |
| 90 | + |
| 91 | +ci: qa coverage docstrings-check docs-check run-example release-check |
| 92 | + |
| 93 | +clean: |
| 94 | + rm -rf .coverage .mypy_cache .pytest_cache .ruff_cache artifacts build dist docs/_build src/design_research_python_template.egg-info |
| 95 | + find . -type d -name "__pycache__" -prune -exec rm -rf {} + 2>/dev/null || true |
| 96 | + find . -type f \( -name "*.pyc" -o -name ".coverage.*" \) -exec rm -f {} + 2>/dev/null || true |
0 commit comments