|
1 | | -# Makefile for pygins project |
| 1 | +# Makefile for l9format-python project |
2 | 2 |
|
3 | | -.PHONY: test format sort lint security-check all |
| 3 | +UNAME_S := $(shell uname -s) |
| 4 | +ifeq ($(UNAME_S),Darwin) |
| 5 | + SED := $(shell command -v gsed 2>/dev/null) |
| 6 | + ifeq ($(SED),) |
| 7 | + $(error GNU sed (gsed) not found on macOS. \ |
| 8 | + Install with: brew install gnu-sed) |
| 9 | + endif |
| 10 | +else |
| 11 | + SED := sed |
| 12 | +endif |
4 | 13 |
|
5 | | -# Run all quality checks |
6 | | -all: test format sort lint security-check |
| 14 | +.PHONY: help |
| 15 | +help: ## Show this help |
| 16 | + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \ |
| 17 | + awk 'BEGIN {FS = ":.*?## "}; \ |
| 18 | + {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
7 | 19 |
|
8 | | -# Run tests using pytest |
9 | | -test: |
| 20 | +.PHONY: all |
| 21 | +all: format sort lint typecheck test security-check ## Run all quality checks |
| 22 | + |
| 23 | +.PHONY: test |
| 24 | +test: ## Run tests using pytest |
10 | 25 | poetry run pytest |
11 | 26 |
|
12 | | -# Format code using black |
13 | | -format: |
| 27 | +.PHONY: format |
| 28 | +format: ## Format code using black |
14 | 29 | poetry run black . |
15 | 30 |
|
16 | | -# Sort imports using isort |
17 | | -sort: |
| 31 | +.PHONY: check-format |
| 32 | +check-format: ## Check code formatting with black |
| 33 | + poetry run black --check . |
| 34 | + |
| 35 | +.PHONY: sort |
| 36 | +sort: ## Sort imports using isort |
18 | 37 | poetry run isort . |
19 | 38 |
|
20 | | -# Lint code using ruff |
21 | | -lint: |
| 39 | +.PHONY: check-sort |
| 40 | +check-sort: ## Check import sorting with isort |
| 41 | + poetry run isort --check-only . |
| 42 | + |
| 43 | +.PHONY: lint |
| 44 | +lint: ## Lint code using ruff |
22 | 45 | poetry run ruff check . |
23 | 46 |
|
24 | | -# Check for vulnerable dependencies using pip-audit |
25 | | -security-check: |
| 47 | +.PHONY: lint-fix |
| 48 | +lint-fix: ## Lint and fix code using ruff |
| 49 | + poetry run ruff check --fix . |
| 50 | + |
| 51 | +.PHONY: typecheck |
| 52 | +typecheck: ## Run mypy type checker |
| 53 | + poetry run mypy l9format |
| 54 | + |
| 55 | +.PHONY: security-check |
| 56 | +security-check: ## Check for vulnerable dependencies using pip-audit |
26 | 57 | poetry run pip-audit |
27 | 58 |
|
| 59 | +.PHONY: fix-trailing-whitespace |
| 60 | +fix-trailing-whitespace: ## Remove trailing whitespaces from all files |
| 61 | + @echo "Removing trailing whitespaces from all files..." |
| 62 | + @find . -type f \( \ |
| 63 | + -name "*.py" -o -name "*.toml" -o -name "*.md" -o -name "*.yaml" \ |
| 64 | + -o -name "*.yml" -o -name "*.json" \) \ |
| 65 | + -not -path "./.git/*" \ |
| 66 | + -not -path "./.venv/*" \ |
| 67 | + -not -path "./__pycache__/*" \ |
| 68 | + -exec sh -c \ |
| 69 | + 'echo "Processing: $$1"; $(SED) -i -e "s/[[:space:]]*$$//" "$$1"' \ |
| 70 | + _ {} \; && \ |
| 71 | + echo "Trailing whitespaces removed." |
| 72 | + |
| 73 | +.PHONY: check-trailing-whitespace |
| 74 | +check-trailing-whitespace: ## Check for trailing whitespaces in source files |
| 75 | + @echo "Checking for trailing whitespaces..." |
| 76 | + @files_with_trailing_ws=$$(find . -type f \( \ |
| 77 | + -name "*.py" -o -name "*.toml" -o -name "*.md" -o -name "*.yaml" \ |
| 78 | + -o -name "*.yml" -o -name "*.json" \) \ |
| 79 | + -not -path "./.git/*" \ |
| 80 | + -not -path "./.venv/*" \ |
| 81 | + -not -path "./__pycache__/*" \ |
| 82 | + -exec grep -l '[[:space:]]$$' {} + 2>/dev/null || true); \ |
| 83 | + if [ -n "$$files_with_trailing_ws" ]; then \ |
| 84 | + echo "Files with trailing whitespaces found:"; \ |
| 85 | + echo "$$files_with_trailing_ws" | sed 's/^/ /'; \ |
| 86 | + echo ""; \ |
| 87 | + echo "Run 'make fix-trailing-whitespace' to fix automatically."; \ |
| 88 | + exit 1; \ |
| 89 | + else \ |
| 90 | + echo "No trailing whitespaces found."; \ |
| 91 | + fi |
| 92 | + |
| 93 | +.PHONY: install |
| 94 | +install: ## Install dependencies with Poetry |
| 95 | + poetry install |
| 96 | + |
| 97 | +.PHONY: clean |
| 98 | +clean: ## Clean build artifacts and caches |
| 99 | + rm -rf __pycache__ .pytest_cache .mypy_cache .ruff_cache |
| 100 | + find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true |
| 101 | + find . -type f -name "*.pyc" -delete 2>/dev/null || true |
0 commit comments