|
| 1 | +# NetSim Development Makefile |
| 2 | + |
| 3 | +.PHONY: help venv clean-venv dev install check check-ci lint format test qt build clean check-dist publish-test publish info hooks check-python |
| 4 | + |
| 5 | +.DEFAULT_GOAL := help |
| 6 | + |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | +# Python interpreter detection |
| 9 | +# -------------------------------------------------------------------------- |
| 10 | +VENV_BIN := $(PWD)/venv/bin |
| 11 | + |
| 12 | +PY_BEST := $(shell for v in 3.14 3.13 3.12 3.11; do command -v python$$v >/dev/null 2>&1 && { echo python$$v; exit 0; }; done; command -v python3 2>/dev/null || command -v python 2>/dev/null) |
| 13 | + |
| 14 | +PY_PATH := $(shell command -v python3 2>/dev/null || command -v python 2>/dev/null) |
| 15 | + |
| 16 | +PYTHON ?= $(if $(wildcard $(VENV_BIN)/python),$(VENV_BIN)/python,$(if $(PY_PATH),$(PY_PATH),$(if $(PY_BEST),$(PY_BEST),python3))) |
| 17 | + |
| 18 | +PIP := $(PYTHON) -m pip |
| 19 | +PYTEST := $(PYTHON) -m pytest |
| 20 | +RUFF := $(PYTHON) -m ruff |
| 21 | +PRECOMMIT := $(PYTHON) -m pre_commit |
| 22 | + |
| 23 | +# -------------------------------------------------------------------------- |
| 24 | +# Help |
| 25 | +# -------------------------------------------------------------------------- |
| 26 | +help: |
| 27 | + @echo "NetSim Development Commands" |
| 28 | + @echo "" |
| 29 | + @echo "Setup:" |
| 30 | + @echo " make venv - Create virtual environment (./venv)" |
| 31 | + @echo " make dev - Full dev setup (venv + deps + pre-commit hooks)" |
| 32 | + @echo " make install - Install package only (no dev deps)" |
| 33 | + @echo " make clean-venv - Remove virtual environment" |
| 34 | + @echo "" |
| 35 | + @echo "Code Quality & Testing:" |
| 36 | + @echo " make check - Pre-commit (auto-fix) + tests + lint" |
| 37 | + @echo " make check-ci - Lint + tests (non-mutating, CI entrypoint)" |
| 38 | + @echo " make lint - Linting only (ruff + pyright)" |
| 39 | + @echo " make format - Auto-format with ruff" |
| 40 | + @echo " make test - Run tests with coverage" |
| 41 | + @echo " make qt - Quick tests (no coverage, no benchmarks)" |
| 42 | + @echo "" |
| 43 | + @echo "Build & Publish:" |
| 44 | + @echo " make build - Build distribution packages" |
| 45 | + @echo " make clean - Clean build artifacts" |
| 46 | + @echo " make check-dist - Check packages with twine" |
| 47 | + @echo " make publish-test - Publish to Test PyPI" |
| 48 | + @echo " make publish - Publish to PyPI" |
| 49 | + @echo "" |
| 50 | + @echo "Utilities:" |
| 51 | + @echo " make info - Show project info" |
| 52 | + @echo " make hooks - Run pre-commit on all files" |
| 53 | + @echo " make check-python - Verify venv Python version" |
| 54 | + |
| 55 | +# -------------------------------------------------------------------------- |
| 56 | +# Setup |
| 57 | +# -------------------------------------------------------------------------- |
| 58 | +dev: |
| 59 | + @echo "Setting up development environment..." |
| 60 | + @if [ ! -x "$(VENV_BIN)/python" ]; then \ |
| 61 | + if [ -z "$(PY_BEST)" ]; then \ |
| 62 | + echo "Error: No Python interpreter found"; \ |
| 63 | + exit 1; \ |
| 64 | + fi; \ |
| 65 | + echo "Creating virtual environment with $(PY_BEST) ..."; \ |
| 66 | + $(PY_BEST) -m venv venv || { echo "Failed to create venv"; exit 1; }; \ |
| 67 | + $(VENV_BIN)/python -m pip install -U pip setuptools wheel; \ |
| 68 | + fi |
| 69 | + @echo "Installing dev dependencies..." |
| 70 | + @$(VENV_BIN)/python -m pip install -e '.[dev]' |
| 71 | + @echo "Installing pre-commit hooks..." |
| 72 | + @$(VENV_BIN)/python -m pre_commit install --install-hooks |
| 73 | + @echo "Dev environment ready. Activate with: source venv/bin/activate" |
| 74 | + @$(MAKE) check-python |
| 75 | + |
| 76 | +venv: |
| 77 | + @if [ -z "$(PY_BEST)" ]; then \ |
| 78 | + echo "Error: No Python interpreter found"; \ |
| 79 | + exit 1; \ |
| 80 | + fi |
| 81 | + @echo "Creating virtual environment with $(PY_BEST) ..." |
| 82 | + @$(PY_BEST) -m venv venv |
| 83 | + @$(VENV_BIN)/python -m pip install -U pip setuptools wheel |
| 84 | + @echo "venv ready. Activate with: source venv/bin/activate" |
| 85 | + |
| 86 | +clean-venv: |
| 87 | + @rm -rf venv/ |
| 88 | + |
| 89 | +install: |
| 90 | + @$(PIP) install -e . |
| 91 | + |
| 92 | +# -------------------------------------------------------------------------- |
| 93 | +# Code Quality & Testing |
| 94 | +# -------------------------------------------------------------------------- |
| 95 | +check: |
| 96 | + @echo "Running complete checks..." |
| 97 | + @$(PRECOMMIT) run --all-files || true |
| 98 | + @$(PRECOMMIT) run --all-files |
| 99 | + @$(MAKE) test |
| 100 | + @$(MAKE) lint |
| 101 | + |
| 102 | +check-ci: |
| 103 | + @echo "Running CI checks (lint + tests)..." |
| 104 | + @$(MAKE) lint |
| 105 | + @$(MAKE) test |
| 106 | + |
| 107 | +lint: |
| 108 | + @$(RUFF) format --check . |
| 109 | + @$(RUFF) check . |
| 110 | + @$(PYTHON) -m pyright |
| 111 | + |
| 112 | +format: |
| 113 | + @$(RUFF) format . |
| 114 | + |
| 115 | +test: |
| 116 | + @$(PYTEST) |
| 117 | + |
| 118 | +qt: |
| 119 | + @$(PYTEST) --no-cov -m "not slow and not benchmark" |
| 120 | + |
| 121 | +hooks: |
| 122 | + @$(PRECOMMIT) run --all-files |
| 123 | + |
| 124 | +# -------------------------------------------------------------------------- |
| 125 | +# Build & Publish |
| 126 | +# -------------------------------------------------------------------------- |
| 127 | +build: |
| 128 | + @$(PYTHON) -m build |
| 129 | + |
| 130 | +clean: |
| 131 | + @rm -rf build/ dist/ *.egg-info/ netsim.egg-info/ |
| 132 | + |
| 133 | +check-dist: |
| 134 | + @$(PYTHON) -m twine check dist/* |
| 135 | + |
| 136 | +publish-test: |
| 137 | + @$(PYTHON) -m twine upload --repository testpypi dist/* |
| 138 | + |
| 139 | +publish: |
| 140 | + @$(PYTHON) -m twine upload dist/* |
| 141 | + |
| 142 | +# -------------------------------------------------------------------------- |
| 143 | +# Utilities |
| 144 | +# -------------------------------------------------------------------------- |
| 145 | +info: |
| 146 | + @echo "Python: $$($(PYTHON) --version 2>&1)" |
| 147 | + @echo "pip: $$($(PIP) --version 2>&1 | head -1)" |
| 148 | + @echo "ruff: $$($(RUFF) --version 2>&1 || echo 'not installed')" |
| 149 | + @echo "pyright: $$($(PYTHON) -m pyright --version 2>&1 || echo 'not installed')" |
| 150 | + @echo "Git: $$(git describe --tags --always 2>/dev/null || echo 'no tags')" |
| 151 | + |
| 152 | +check-python: |
| 153 | + @VENV_PY=$$($(VENV_BIN)/python --version 2>&1 | awk '{print $$2}' | cut -d. -f1,2); \ |
| 154 | + BEST_PY=$$($(PY_BEST) --version 2>&1 | awk '{print $$2}' | cut -d. -f1,2); \ |
| 155 | + if [ "$$VENV_PY" != "$$BEST_PY" ]; then \ |
| 156 | + echo "Warning: venv uses Python $$VENV_PY but $$BEST_PY is available"; \ |
| 157 | + echo "Run: make clean-venv && make dev"; \ |
| 158 | + fi |
0 commit comments