|
| 1 | +## Makefile — PyPortfolioOpt developer conveniences |
| 2 | +# |
| 3 | +# This Makefile exposes common local development tasks and a friendly |
| 4 | +# `make help` index. |
| 5 | +# Conventions used by the help generator: |
| 6 | +# - Lines with `##` after a target are turned into help text. |
| 7 | +# - Lines starting with `##@` create section headers in the help output. |
| 8 | +# This file does not affect the library itself; it only streamlines dev workflows. |
| 9 | + |
| 10 | +# Colors for pretty output in help messages |
| 11 | +BLUE := \033[36m |
| 12 | +BOLD := \033[1m |
| 13 | +GREEN := \033[32m |
| 14 | +RED := \033[31m |
| 15 | +RESET := \033[0m |
| 16 | + |
| 17 | +# Default goal when running `make` with no target |
| 18 | +.DEFAULT_GOAL := help |
| 19 | + |
| 20 | +# Declare phony targets (they don't produce files) |
| 21 | +.PHONY: install install-uv test fmt |
| 22 | + |
| 23 | +UV_INSTALL_DIR := ./bin |
| 24 | + |
| 25 | +##@ Bootstrap |
| 26 | +install-uv: ## ensure uv (and uvx) are installed locally |
| 27 | + @mkdir -p ${UV_INSTALL_DIR} |
| 28 | + @if [ -x "${UV_INSTALL_DIR}/uv" ] && [ -x "${UV_INSTALL_DIR}/uvx" ]; then \ |
| 29 | + :; \ |
| 30 | + else \ |
| 31 | + printf "${BLUE}Installing uv${RESET}\n"; \ |
| 32 | + curl -LsSf https://astral.sh/uv/install.sh | UV_INSTALL_DIR=${UV_INSTALL_DIR} sh 2>/dev/null || { printf "${RED}[ERROR] Failed to install uv ${RESET}\n"; exit 1; }; \ |
| 33 | + fi |
| 34 | + |
| 35 | +install: install-uv ## install |
| 36 | + @printf "${BLUE}[INFO] Creating virtual environment...${RESET}\n" |
| 37 | + # Create the virtual environment |
| 38 | + @./bin/uv venv --python 3.12 || { printf "${RED}[ERROR] Failed to create virtual environment${RESET}\n"; exit 1; } |
| 39 | + @printf "${BLUE}[INFO] Installing dependencies${RESET}\n" |
| 40 | + @./bin/uv sync --all-extras --frozen || { printf "${RED}[ERROR] Failed to install dependencies${RESET}\n"; exit 1; } |
| 41 | + |
| 42 | + |
| 43 | +##@ Development and Testing |
| 44 | +test: install ## run all tests |
| 45 | + @printf "${BLUE}[INFO] Running tests...${RESET}\n" |
| 46 | + @./bin/uv pip install pytest pytest-cov pytest-html |
| 47 | + @mkdir -p _tests/html-coverage _tests/html-report |
| 48 | + @./bin/uv run pytest tests --cov=pypfopt --cov-report=term --cov-report=html:_tests/html-coverage --html=_tests/html-report/report.html |
| 49 | + |
| 50 | +fmt: install-uv ## check the pre-commit hooks and the linting |
| 51 | + @./bin/uvx pre-commit run --all-files |
| 52 | + @./bin/uvx deptry . |
| 53 | + |
| 54 | +##@ Meta |
| 55 | +help: ## Display this help message |
| 56 | + +@printf "$(BOLD)Usage:$(RESET)\n" |
| 57 | + +@printf " make $(BLUE)<target>$(RESET)\n\n" |
| 58 | + +@printf "$(BOLD)Targets:$(RESET)\n" |
| 59 | + +@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_-]+:.*?##/ { printf " $(BLUE)%-15s$(RESET) %s\n", $$1, $$2 } /^##@/ { printf "\n$(BOLD)%s$(RESET)\n", substr($$0, 5) }' $(MAKEFILE_LIST) |
0 commit comments