-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
307 lines (254 loc) · 11.4 KB
/
Copy pathMakefile
File metadata and controls
307 lines (254 loc) · 11.4 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# notewise Makefile
# Cross-platform development workflow for Linux, macOS, and Windows
# ==============================================================================
# Platform Detection
# ==============================================================================
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
SHELL := cmd.exe
.SHELLFLAGS := /c
DEVNULL := NUL
OPEN := start
RM_FILE := del /Q /F
RM_DIR := rmdir /S /Q
FIND_PYCACHE := for /d /r . %%d in (__pycache__) do @if exist "%%d" $(RM_DIR) "%%d" 2>$(DEVNULL)
FIND_CACHE := for /d /r . %%d in (.ruff_cache .ty_cache .pytest_cache) do @if exist "%%d" $(RM_DIR) "%%d" 2>$(DEVNULL)
FIND_EGG := for /d /r . %%d in (*.egg-info) do @if exist "%%d" $(RM_DIR) "%%d" 2>$(DEVNULL)
FIND_EMPTY_DIRS := powershell -NoProfile -Command "Get-ChildItem -Directory -Recurse | Where-Object { (Get-ChildItem -Force -LiteralPath $${PSItem}.FullName | Measure-Object).Count -eq 0 -and $${PSItem}.FullName -notmatch '\\.venv\\' } | Sort-Object FullName -Descending | ForEach-Object { Remove-Item -LiteralPath $${PSItem}.FullName -Force -Recurse }"
FIND_PYC := del /S /Q *.pyc *.pyo 2>$(DEVNULL) || echo >$(DEVNULL)
CHECK_DIR = @if exist $(1) $(RM_DIR) $(1) 2>$(DEVNULL)
CHECK_FILE = @if exist $(1) $(RM_FILE) $(1) 2>$(DEVNULL)
PYTHON_CMD := python
else
DETECTED_OS := $(shell uname -s)
SHELL := /bin/sh
.SHELLFLAGS := -c
DEVNULL := /dev/null
RM_FILE := rm -f
RM_DIR := rm -rf
FIND_PYCACHE := find . -type d -name "__pycache__" -exec rm -rf {} + 2>$(DEVNULL) || true
FIND_CACHE := find . -type d \( -name ".ruff_cache" -o -name ".ty_cache" -o -name ".pytest_cache" \) -exec rm -rf {} + 2>$(DEVNULL) || true
FIND_EGG := find . -type d -name "*.egg-info" -exec rm -rf {} + 2>$(DEVNULL) || true
FIND_EMPTY_DIRS := find . -type d -empty -not -path "./.venv/*" -not -path "./.venv" -exec rmdir {} + 2>$(DEVNULL) || true
FIND_PYC := find . -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete 2>$(DEVNULL) || true
CHECK_DIR = @$(RM_DIR) $(1) 2>$(DEVNULL) || true
CHECK_FILE = @$(RM_FILE) $(1) 2>$(DEVNULL) || true
PYTHON_CMD := python3
ifeq ($(DETECTED_OS),Darwin)
OPEN := open
else ifeq ($(DETECTED_OS),Linux)
OPEN := xdg-open
else
OPEN := echo "Open manually:"
endif
endif
.DEFAULT_GOAL := help
.DELETE_ON_ERROR:
.SUFFIXES:
# ==============================================================================
# Tool Configuration
# ==============================================================================
UV := uv
UV_RUN := $(UV) run
PIP := $(UV) pip
PRE_COMMIT := $(UV_RUN) pre-commit
RUFF := $(UV_RUN) ruff
TY := $(UV_RUN) ty
PYTEST := $(UV) run --no-sync python -m pytest
PYTEST_WATCH := $(UV_RUN) --with pytest-watch ptw
PYTEST_PARALLEL_FLAGS := -n auto --dist=loadfile
DEPTRY := $(UV_RUN) deptry
BANDIT := $(UV_RUN) bandit
TWINE := $(UV_RUN) --with twine twine
HELP_SCRIPT := scripts/make_help.py
# ==============================================================================
# Directory Configuration
# ==============================================================================
SRC_DIR := src
PKG_DIR := src/notewise
SCRIPTS_DIR := scripts
TEST_DIR := tests
UNIT_TEST_DIR := $(TEST_DIR)/unit
INTEGRATION_TEST_DIR := $(TEST_DIR)/integration
PY_FILES := $(PKG_DIR) $(TEST_DIR) $(SCRIPTS_DIR)
BUILD_DIR := build
DIST_DIR := dist
HTMLCOV_DIR := htmlcov
MAKEFILE_PATH := $(firstword $(MAKEFILE_LIST))
# ==============================================================================
# Shared Command Arguments
# ==============================================================================
PYTEST_ALL := $(PYTEST) $(TEST_DIR) $(PYTEST_PARALLEL_FLAGS)
COVERAGE_TERM_ARGS := --cov=$(PKG_DIR) --cov-report=term-missing
COVERAGE_CI_ARGS := $(COVERAGE_TERM_ARGS) --cov-fail-under=90 --cov-report=xml --cov-report=html
# ==============================================================================
# Target Groups
# ==============================================================================
QUALITY_CHECK_TARGETS := format-check lint-check type-check version-check deps-check security
QUALITY_FIX_TARGETS := format lint type-check version-check deps-check security
CLEAN_TARGETS := clean-cache clean-build clean-test
# ==============================================================================
# Phony Targets
# ==============================================================================
.PHONY: help sync install install-dev dev-setup \
format format-check lint lint-check type-check version-check deps-check security \
check verify fix audit quality pre-commit \
hooks-install hooks-run \
test test-unit test-integration test-fast test-cov test-watch test-failed test-verbose \
coverage-open \
build publish publish-test \
show-deps show-outdated update-deps \
$(CLEAN_TARGETS) clean-empty-dirs clean clean-all \
all ci quick info
# ==============================================================================
# Help
# ==============================================================================
##@ Help
help: ## Show all developer tasks
@$(PYTHON_CMD) $(HELP_SCRIPT) "$(DETECTED_OS)" "$(MAKEFILE_PATH)"
# ==============================================================================
# Setup
# ==============================================================================
##@ Setup
sync: ## Install all dependencies from lockfile
$(UV) sync --all-extras --dev --frozen
install: ## Install package in editable mode
$(PIP) install -e .
install-dev: ## Install package + dev dependencies + hooks
$(PIP) install -e .
$(UV) sync --all-extras --dev --frozen
$(MAKE) hooks-install
dev-setup: install-dev ## Full contributor setup (alias for install-dev)
# ==============================================================================
# Code Quality - Formatting
# ==============================================================================
##@ Code Quality
format: ## Format code with ruff
$(RUFF) format $(PY_FILES)
format-check: ## Check code formatting
$(RUFF) format --check $(PY_FILES)
# ==============================================================================
# Code Quality - Linting
# ==============================================================================
lint: ## Run ruff with auto-fix
$(RUFF) check $(PY_FILES) --fix --unsafe-fixes
lint-check: ## Run ruff without auto-fix
$(RUFF) check $(PY_FILES)
# ==============================================================================
# Code Quality - Type Checking & Security
# ==============================================================================
type-check: ## Run ty type checker
$(TY) check $(PKG_DIR)
version-check: ## Verify package version metadata is aligned
$(UV_RUN) python scripts/check_version_sync.py
deps-check: ## Detect unused/missing dependencies
$(DEPTRY) $(SRC_DIR)
security: ## Run security scan with bandit
$(BANDIT) -c pyproject.toml -r $(PKG_DIR) --severity-level medium --confidence-level medium
# ==============================================================================
# Code Quality - Bundles
# ==============================================================================
check: $(QUALITY_CHECK_TARGETS) ## Run all quality checks (CI-safe)
quality: check ## Alias for check
verify: $(QUALITY_FIX_TARGETS) ## Run all quality checks with auto-fixes
fix: format lint ## Auto-fix formatting and lint issues
audit: deps-check security ## Run deps-check + security
# ==============================================================================
# Git Hooks
# ==============================================================================
##@ Git Hooks
hooks-install: ## Install pre-commit hooks
$(PRE_COMMIT) install --hook-type pre-commit --hook-type pre-push --hook-type commit-msg
hooks-run: ## Run pre-commit hooks on all files
$(PRE_COMMIT) run --all-files
$(PRE_COMMIT) run --hook-stage pre-push --all-files
pre-commit: check test-fast ## Run checks + fast tests before commit
# ==============================================================================
# Testing
# ==============================================================================
##@ Testing
test: ## Run full test suite
$(PYTEST_ALL) -v
test-unit: ## Run unit tests with coverage
$(PYTEST) $(UNIT_TEST_DIR) $(PYTEST_PARALLEL_FLAGS) $(COVERAGE_TERM_ARGS) -v
test-integration: ## Run integration tests
$(PYTEST) $(INTEGRATION_TEST_DIR) $(PYTEST_PARALLEL_FLAGS) -v
test-fast: ## Run tests in quiet mode
$(PYTEST_ALL) -q
test-cov: ## Run tests with coverage report
$(PYTEST_ALL) $(COVERAGE_CI_ARGS) -v
@echo ""
@echo "Coverage reports generated:"
@echo " HTML: $(HTMLCOV_DIR)/index.html"
@echo " XML: coverage.xml"
coverage-open: test-cov ## Generate and open HTML coverage report
@$(OPEN) $(HTMLCOV_DIR)/index.html 2>$(DEVNULL) || echo "Open $(HTMLCOV_DIR)/index.html manually"
test-watch: ## Run tests in watch mode
$(PYTEST_WATCH) $(TEST_DIR) -v
test-failed: ## Re-run only failed tests
$(PYTEST_ALL) --lf -v
test-verbose: ## Run tests with maximal verbosity
$(PYTEST) $(TEST_DIR) -vv -s
# ==============================================================================
# Build & Publish
# ==============================================================================
##@ Build & Publish
build: clean-build ## Build wheel and source distribution
$(UV) build
publish: build ## Publish to PyPI
$(TWINE) check $(DIST_DIR)/*
$(TWINE) upload $(DIST_DIR)/*
publish-test: build ## Publish to TestPyPI
$(TWINE) upload --repository testpypi $(DIST_DIR)/*
# ==============================================================================
# Dependency Management
# ==============================================================================
##@ Info
show-deps: ## Show installed dependencies
$(UV) pip list
show-outdated: ## Show outdated dependencies
$(UV) pip list --outdated
update-deps: ## Update dependencies and lockfile
$(UV) sync --all-extras --dev
# ==============================================================================
# Cleanup
# ==============================================================================
##@ Cleanup
clean-cache: ## Remove Python and tool caches
@$(FIND_PYCACHE)
@$(FIND_CACHE)
@$(FIND_PYC)
clean-build: ## Remove build artifacts
$(call CHECK_DIR,$(BUILD_DIR))
$(call CHECK_DIR,$(DIST_DIR))
@$(FIND_EGG)
clean-test: ## Remove test artifacts
$(call CHECK_DIR,$(HTMLCOV_DIR))
$(call CHECK_FILE,.coverage)
$(call CHECK_FILE,coverage.xml)
clean-empty-dirs: ## Remove empty directories created by build and refactor churn
@$(FIND_EMPTY_DIRS)
clean: $(CLEAN_TARGETS) clean-empty-dirs ## Remove all generated files
clean-all: clean ## Remove generated files and virtualenvs
$(call CHECK_DIR,.venv)
$(call CHECK_DIR,venv)
$(call CHECK_DIR,env)
# ==============================================================================
# Info
# ==============================================================================
##@ Info
info: ## Show tool and interpreter versions
@echo "OS: $(DETECTED_OS)"
@echo ""
@$(PYTHON_CMD) --version 2>$(DEVNULL) || echo "Python: not found"
@$(UV) --version 2>$(DEVNULL) || echo "uv: not found"
@$(RUFF) --version 2>$(DEVNULL) || echo "ruff: not found"
@$(TY) --version 2>$(DEVNULL) || echo "ty: not found"
@$(PYTEST) --version 2>$(DEVNULL) || echo "pytest: not found"
# ==============================================================================
# Workflow Bundles
# ==============================================================================
##@ Workflow Bundles
quick: format-check lint-check test-fast ## Fast pre-push validation
ci: check test-cov ## CI-equivalent validation
all: ci ## Alias for ci