-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
169 lines (139 loc) · 5.34 KB
/
makefile
File metadata and controls
169 lines (139 loc) · 5.34 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
# Makefile — project automation
# ATTENTION: Use TABS (not spaces) to indent recipe commands.
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
.ONESHELL:
.DELETE_ON_ERROR:
version:
# ---- Configurable variables ----
PYTHON ?= python3
PACKAGE ?= PythonRuns
#INDEX_URL ?= https://nexus.myrepo.net/repository/pypi-releases/simple # when using private repo (e.g., Nexus)
INDEX_URL ?= https://pypi.org/simple
EXTRA_INDEX_URL ?= https://pypi.org/simple
REPOSITORY_UPLOAD ?= https://nexus.myrepo.net/repository/pypi-releases/
UV_FLAGS := --index-url $(INDEX_URL) --extra-index-url $(EXTRA_INDEX_URL)
# ---- Colors ----
C_CYAN := \033[1;36m
C_GREEN := \033[1;32m
C_RST := \033[0m
# ---- Logging helpers ----
define log_start
@SECONDS=0; printf "\n$(C_CYAN)[%s] ▶ Starting %s$(C_RST)\n" "$$(date +'%F %T')" "$(1)"
endef
define log_done
@printf "$(C_GREEN)✓ Done %s in %ss$(C_RST)\n" "$(1)" "$$SECONDS"
endef
.PHONY: sync install config update test test-coverage run pre-commit build deploy version help list clean \
check-dist twine-check check-tools check-pytest check-precommit check-twine check-build check-uv \
requirements requirements-clean
# ---- Guard checks ----
check-uv:
@command -v uv >/dev/null || { echo "uv not found. Install: curl -LsSf https://astral.sh/uv/install.sh | sh"; exit 1; }
check-dist: ## Ensure ./dist exists and contains artifacts
$(call log_start,$@)
@test -d dist || { echo "No 'dist/' directory. Run 'make build' first."; exit 1; }
@test -n "$$(ls -A dist 2>/dev/null)" || { echo "'dist/' is empty. Run 'make build' first."; exit 1; }
$(call log_done,$@)
twine-check: check-dist check-twine ## Validate built artifacts (sdist/wheel) with Twine
$(call log_start,$@)
twine check dist/*
$(call log_done,$@)
# ---- Target-specific tool checks ----
check-pytest:
@command -v pytest >/dev/null || { echo "pytest not found. Run 'uv sync --all-groups' or 'make sync'"; exit 1; }
check-precommit:
@command -v pre-commit >/dev/null || { echo "pre-commit not found. Run 'uv sync --all-groups'"; exit 1; }
check-twine:
@command -v twine >/dev/null || { echo "twine not found. Run 'uv pip install --system twine'"; exit 1; }
check-build:
@$(PYTHON) -c "import build" 2>/dev/null || { echo "build module not found. Run 'uv pip install --system build'"; exit 1; }
# Optional: quick all-in-one diagnostic
check-tools: ## Check common CLI tools are available
$(call log_start,$@)
command -v pip >/dev/null
command -v $(PYTHON) >/dev/null
command -v awk >/dev/null
$(MAKE) check-pytest || true
$(MAKE) check-precommit || true
$(MAKE) check-twine || true
$(MAKE) check-build || true
$(call log_done,$@)
# ---- Targets ----
config: ## Configure pip indexes (optional, for legacy pip usage)
$(call log_start,$@)
pip config --user set global.index-url $(INDEX_URL)
pip config --user set global.extra-index-url $(EXTRA_INDEX_URL)
pip config --user list
$(call log_done,$@)
clean: ## Remove build/test artifacts
$(call log_start,$@)
rm -rf dist build .pytest_cache .mypy_cache .coverage htmlcov report.html
find . -type d -name "__pycache__" -exec rm -rf {} \;
find . -type d -name "*.egg-info" -exec rm -rf {} \;
$(call log_done,$@)
sync: check-uv ## Sync dependencies from uv.lock (recommended)
$(call log_start,$@)
uv sync
$(call log_done,$@)
install: check-uv ## Install project with uv (creates venv and syncs dependencies)
$(call log_start,$@)
uv venv || true
uv sync
$(call log_done,$@)
update: check-uv ## Update dependencies and regenerate lockfile
$(call log_start,$@)
uv lock --upgrade
uv sync
$(call log_done,$@)
requirements: check-uv ## Export requirements.txt from pyproject.toml
$(call log_start,$@)
uv pip compile pyproject.toml -o requirements.txt $(UV_FLAGS)
$(call log_done,$@)
requirements-clean: ## Delete requirements.txt
$(call log_start,$@)
rm -f requirements.txt
@echo "requirements.txt deleted"
$(call log_done,$@)
test: check-pytest ## Run tests (verbose)
$(call log_start,$@)
pytest --verbose
$(call log_done,$@)
test-coverage: check-pytest ## Run tests with coverage; HTML at ./report.html
$(call log_start,$@)
pytest --cov=$(PACKAGE) --verbose --html=report.html --self-contained-html
$(call log_done,$@)
run: ## Run the package as a module
$(call log_start,$@)
$(PYTHON) -m $(PACKAGE)
$(call log_done,$@)
pre-commit: check-precommit ## Run all pre-commit hooks
$(call log_start,$@)
pre-commit run --all-files
$(call log_done,$@)
build: check-build clean ## Build sdist and wheel into ./dist
$(call log_start,$@)
$(PYTHON) -m build
$(call log_done,$@)
deploy: twine-check ## Upload ./dist to Nexus (uses TWINE_* env vars)
$(call log_start,$@)
twine upload --repository-url $(REPOSITORY_UPLOAD) dist/*
$(call log_done,$@)
version: ## Show package version
$(call log_start,$@)
$(PACKAGE) -v
$(call log_done,$@)
help: ## List available commands (default)
@awk 'BEGIN {FS = ":.*## " } \
/^[a-zA-Z0-9_.-]+:.*## / { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 }' \
$(MAKEFILE_LIST)
list: help ## Alias for help
# ======================== HOW TO USE ========================
# List commands (with descriptions): make OR make help
# Safer deploy: export TWINE_USERNAME / TWINE_PASSWORD (or token) before `make deploy`
# Examples:
# make install
# make update
# make test-coverage
# make build && make twine-check && make deploy