-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (110 loc) · 3.36 KB
/
Copy pathMakefile
File metadata and controls
131 lines (110 loc) · 3.36 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
# Run 'make help' to see guidance on usage of this Makefile
# Load .env file if any, for secrets+values (string value, scripts fail in .env)
ifneq (,$(wildcard ./.env))
include .env
export
endif
# Variables set as fallback: descending priority is:
# - 'make' invocation-level overrides
# - values stored in .env, loaded
# - Fallback values using ?=, see below:
DOCKER_IMAGE_NAME?=aoc2025
DOCKER_REGISTRY?=
APP_VERSION?=$(shell uv version --short)
## Default command, run via 'make' or 'make all'
.PHONY: all
all: install lint test docs build install-hooks
## Generate the help message by reading the Makefile
.PHONY: help
help:
@echo "This makefile contains the following targets, from most commonly used to least: (docs first, then target name)"
@awk \
'/^##/ {sub(/## */,""); print} \
/^[a-z0-9-]+:/ && !/.PHONY:/ \
{sub(/:.*/, ""); print "⮡ \033[31;1;4m" $$0 "\033[0m\n" }' \
Makefile
## Set up the virtualenv and install the package + dependencies
.PHONY: install
install:
uv sync
## Run the linters and formatters on all files (not just staged for commit)
.PHONY: lint
lint:
pre-commit run --all --all-files
## Run the tests
.PHONY: test
test:
uv run pytest
## Generate the docs, both HTML and docsets
.PHONY: docs
docs:
cd docs && make html
uv run \
doc2dash \
--force \
--name aoc2025 \
docs/build/html \
--destination docs/build/docset
## Serve the generated docs on a port of localhost
.PHONY: docs-serve
docs-serve:
cd docs/build/html && python3 -m http.server
## Build the wheel/tarball package
.PHONY: build
build:
uv build
## Set up the pre-commit hooks to execute on next git commit
.PHONY: install-hooks
install-hooks:
pre-commit install
## Build the 'release' docker image (just the package installed)
.PHONY: docker-build-release
docker-build-release:
docker build \
-t "${DOCKER_REGISTRY}${DOCKER_IMAGE_NAME}:${APP_VERSION}" \
-f release.Dockerfile \
.
## Build the 'dev' docker image (all tools and code)
.PHONY: docker-build-dev
docker-build-dev:
docker build -t ${DOCKER_IMAGE_NAME}-dev .
## Make a release commit + tag, creating Changelog entry
## Set BUMP variable to any of uv-supported (major, minor, patch)
## Default the bump to a patch (v1.2.3 -> v1.2.4)
BUMP=minor
.PHONY: release
release:
# Set the new version Makefile variable after the version bump
$(eval NEW_VERSION := $(shell uv version --short --bump ${BUMP}))
$(eval TMP_CHANGELOG := $(shell mktemp))
@sed \
"s;\(## \[Unreleased\]\);\1\n\n## v${NEW_VERSION} - $(shell date +%Y-%m-%d);" \
CHANGELOG.md > ${TMP_CHANGELOG}
@mv --force ${TMP_CHANGELOG} CHANGELOG.md
uv lock
git add CHANGELOG.md pyproject.toml uv.lock
git commit -m "Bump to version v${NEW_VERSION}"
git tag --annotate "v${NEW_VERSION}" \
--message "Release v${NEW_VERSION}"
## Less commonly used commands
## Generate/update the uv.lock file
.PHONY: lock
lock:
uv lock
## Update dependencies (within pyproject.toml specs)
## Update the lock-file at the same time
.PHONY: update
update:
uv lock --upgrade
## Install tools (uv, pre-commit) via pipx
## Assumes you have pipx installed
# See https://jiby.tech/post/my-python-toolbox/#pipx-for-cli-installs-not-pip
.PHONY: install-tools
install-tools:
uv self version
uv tool install pre-commit
## Delete the virtualenv to clean dependencies
## Useful when switching to a branch with less dependencies
.PHONY: venv-nuke
venv-nuke:
find .venv -delete