-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (111 loc) · 3.73 KB
/
Makefile
File metadata and controls
133 lines (111 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Makefile for l9format-python project
VERSION := $(shell poetry version -s)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED := $(shell command -v gsed 2>/dev/null)
ifeq ($(SED),)
$(error GNU sed (gsed) not found on macOS. \
Install with: brew install gnu-sed)
endif
else
SED := sed
endif
.PHONY: help
help: ## Show this help
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: all
all: format sort lint typecheck test security-check ## Run all quality checks
.PHONY: test
test: ## Run tests using pytest
poetry run pytest
.PHONY: format
format: ## Format code using black
poetry run black .
.PHONY: check-format
check-format: ## Check code formatting with black
poetry run black --check .
.PHONY: sort
sort: ## Sort imports using isort
poetry run isort .
.PHONY: check-sort
check-sort: ## Check import sorting with isort
poetry run isort --check-only .
.PHONY: lint
lint: ## Lint code using ruff
poetry run ruff check .
.PHONY: lint-fix
lint-fix: ## Lint and fix code using ruff
poetry run ruff check --fix .
.PHONY: lint-shell
lint-shell: ## Lint shell scripts using shellcheck
shellcheck .github/scripts/*.sh
.PHONY: typecheck
typecheck: ## Run mypy type checker
poetry run mypy l9format
.PHONY: security-check
security-check: ## Check for vulnerable dependencies using pip-audit
poetry run pip-audit
.PHONY: fix-trailing-whitespace
fix-trailing-whitespace: ## Remove trailing whitespaces from all files
@echo "Removing trailing whitespaces from all files..."
@find . -type f \( \
-name "*.py" -o -name "*.toml" -o -name "*.md" -o -name "*.yaml" \
-o -name "*.yml" -o -name "*.json" \) \
-not -path "./.git/*" \
-not -path "./.venv/*" \
-not -path "./__pycache__/*" \
-exec sh -c \
'echo "Processing: $$1"; $(SED) -i -e "s/[[:space:]]*$$//" "$$1"' \
_ {} \; && \
echo "Trailing whitespaces removed."
.PHONY: check-trailing-whitespace
check-trailing-whitespace: ## Check for trailing whitespaces in source files
@echo "Checking for trailing whitespaces..."
@files_with_trailing_ws=$$(find . -type f \( \
-name "*.py" -o -name "*.toml" -o -name "*.md" -o -name "*.yaml" \
-o -name "*.yml" -o -name "*.json" \) \
-not -path "./.git/*" \
-not -path "./.venv/*" \
-not -path "./__pycache__/*" \
-exec grep -l '[[:space:]]$$' {} + 2>/dev/null || true); \
if [ -n "$$files_with_trailing_ws" ]; then \
echo "Files with trailing whitespaces found:"; \
echo "$$files_with_trailing_ws" | sed 's/^/ /'; \
echo ""; \
echo "Run 'make fix-trailing-whitespace' to fix automatically."; \
exit 1; \
else \
echo "No trailing whitespaces found."; \
fi
.PHONY: install
install: ## Install dependencies with Poetry
poetry install
.PHONY: build
build: clean-dist ## Build package for distribution
poetry build
.PHONY: publish-dry-run
publish-dry-run: build ## Dry-run: show what would be published
@echo "Would publish l9format v$(VERSION)"
@echo "Would create tag: v$(VERSION)"
@echo "Would create GitHub release: v$(VERSION)"
@echo "Package contents:"
@ls -lh dist/
poetry publish --dry-run
.PHONY: publish
publish: build ## Publish to PyPI, tag and create GitHub release
poetry publish
git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
git push origin "v$(VERSION)"
gh release create "v$(VERSION)" dist/* \
--title "v$(VERSION)" \
--notes "Release v$(VERSION)"
.PHONY: clean-dist
clean-dist: ## Clean distribution artifacts
rm -rf dist/
.PHONY: clean
clean: clean-dist ## Clean build artifacts and caches
rm -rf __pycache__ .pytest_cache .mypy_cache .ruff_cache
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true