This repository was archived by the owner on Feb 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
Β·364 lines (303 loc) Β· 10.2 KB
/
run
File metadata and controls
executable file
Β·364 lines (303 loc) Β· 10.2 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/env bash
#
# usage: ./run.sh command [argument ...]
#
# Commands used during development / CI.
# Also, executable documentation for project dev practices.
#
# See https://death.andgravity.com/run-sh
# for an explanation of how it works and why it's useful.
# First, set up the environment.
# (Check the notes at the end when changing this.)
set -o nounset
set -o pipefail
set -o errexit
# Enable this to echo commands as they are executed.
#set -o xtrace
# Change the current directory to the project root.
PROJECT_ROOT=${0%/*}
if [[ $0 != $PROJECT_ROOT && $PROJECT_ROOT != "" ]]; then
cd "$PROJECT_ROOT"
fi
readonly PROJECT_ROOT=$(pwd)
# Store the absolute path to this script (useful for recursion).
readonly SCRIPT="$PROJECT_ROOT/$(basename "$0")"
################################################################################
# Core Development Commands
function install {
#@ Install project dependencies and create virtual environment
#@ Category: Core Development
uv sync
uv lock
}
function sync {
#@ Install dependencies from lock file
#@ Category: Core Development
uv sync
}
function lint {
#@ Run linting (ruff check/format + mypy type checking)
#@ Category: Core Development
uv run ruff check src
uv run ruff format --check src
mypy # Call mypy function
}
function format {
#@ Auto-format code with ruff
#@ Category: Core Development
uv run ruff check --fix src
uv run ruff format src
}
function mypy {
#@ Run type checking only
#@ Category: Core Development
uv run mypy --config-file pyproject.toml src
}
function test {
#@ Run all tests with pytest
#@ Category: Core Development
if [ $# -eq 0 ]; then
# If no arguments provided, run tests only in tests/ directory to avoid config conflicts
uv run pytest tests/
else
# If arguments provided, pass them through
uv run pytest "$@"
fi
}
function clean {
#@ Remove temporary files and caches
#@ Category: Core Development
pycache-remove
dsstore-remove
mypycache-remove
ipynbcheckpoints-remove
pytestcache-remove
build-remove
}
function version {
#@ Show current project version
#@ Category: Core Development
cat VERSION
}
function bumpversion {
#@ Bump version using bumpversion tool
#@ Usage: bumpversion [patch|minor|major] or bumpversion --new-version X.Y.Z patch
#@ Category: Core Development
command bumpversion "$@"
}
################################################################################
# Package Management Commands
function build-deb {
#@ Build Debian package (run inside devtools container)
#@ Category: Package Management
echo "ποΈ Building Debian package..."
# Create a build area with the project as a subdirectory
# This allows dpkg-buildpackage to write to the parent directory
BUILD_AREA=$(mktemp -d)
PROJECT_NAME=$(basename "$PWD")
# Copy source to build area
cp -a . "$BUILD_AREA/$PROJECT_NAME"
cd "$BUILD_AREA/$PROJECT_NAME"
# Build the package
uv sync
dpkg-buildpackage -us -uc -b
# Move artifacts back to original directory
mv "$BUILD_AREA"/*.deb "$BUILD_AREA"/*.buildinfo "$BUILD_AREA"/*.changes "$OLDPWD/" 2>/dev/null || true
# Cleanup
rm -rf "$BUILD_AREA"
echo "β
Debian package built successfully"
}
function build {
#@ Build Debian package in Docker container
#@ Category: Package Management
echo "π³ Building Debian package using Docker..."
devtools ./run build-deb
echo "β
Build complete - packages in current directory"
}
function build-docker {
#@ Build development Docker image
#@ Category: Package Management
echo "π³ Building development Docker image..."
docker compose -f docker/docker-compose.devtools.yml build devtools
echo "β
Docker image built successfully"
}
################################################################################
# Docker Commands
function devtools {
#@ Run command in devtools container
#@ Usage: devtools <command> [args]
#@ Category: Docker
docker compose -f docker/docker-compose.devtools.yml run --rm devtools "$@"
}
function docker-shell {
#@ Open interactive shell in development container
#@ Category: Docker
echo "π Opening shell in development container..."
echo " Working directory: /workspace"
echo " Exit with: exit or Ctrl+D"
echo ""
devtools bash
}
function docker-clean {
#@ Remove development Docker containers and images
#@ Category: Docker
echo "π§Ή Cleaning Docker containers and images..."
docker compose -f docker/docker-compose.devtools.yml down --rmi all --volumes
echo "β
Docker cleanup complete"
}
################################################################################
# Testing/CI Commands
function ci-check {
#@ Run CI verification checks (lint + test)
#@ Category: Testing/CI
echo "π Running CI verification checks..."
lint
test
echo "β
CI checks passed"
}
function ci-build {
#@ Full CI build pipeline (lint + test + package)
#@ Category: Testing/CI
echo "π Running full CI build pipeline..."
clean
ci-check
build
echo "β
CI build pipeline completed successfully"
}
################################################################################
# Development Utilities Commands
function update-dev-deps {
#@ Update development dependencies to latest versions
#@ Category: Development Utilities
uv add --dev ruff mypy mypy-extensions
}
function update-bindings {
#@ Update I2C bindings from firmware repo
#@ Category: Development Utilities
rm -rf src/halpi2_fw_i2c_postcard
pushd ../HALPI2-firmware || { echo "Error: ../HALPI2-firmware not found"; exit 1; }
./run generate-bindings
popd
cp -a ../HALPI2-firmware/halpi2-fw-i2c-postcard/src/halpi2_fw_i2c_postcard src/
}
function push {
#@ Push code to remote development server
#@ Category: Development Utilities
rsync -avP --delete --exclude-from='.gitignore' \
--exclude='.venv' . halpi2:src/halpid/
}
function pull {
#@ Pull code from remote development server
#@ Category: Development Utilities
rsync -avP --delete --exclude-from='.gitignore' \
--exclude='.venv' halpi2:src/halpid/ .
}
function bumpversion-dry-run {
#@ Preview version change without applying
#@ Usage: bumpversion-dry-run <version>
#@ Category: Development Utilities
local new_version="${1:-}"
if [ -z "$new_version" ]; then
echo "Error: Version required. Usage: bumpversion-dry-run <new_version>"
echo "Current version: $(version)"
echo "Example: ./run bumpversion-dry-run 3.2.0"
exit 1
fi
echo "Current version: $(version)"
echo "Preview of changes for version $new_version:"
bump2version --new-version "$new_version" patch --dry-run --verbose
}
################################################################################
# Setup/Installation Commands
function install-uv {
#@ Download and install the latest version of uv
#@ Category: Setup/Installation
curl -LsSf https://astral.sh/uv/install.sh | sh
}
################################################################################
# Internal cleanup functions (not shown in main help)
function pycache-remove {
find . -type d -name __pycache__ -exec rm -r {} + 2>/dev/null || true
}
function dsstore-remove {
find . -type f -name .DS_Store -exec rm {} + 2>/dev/null || true
}
function mypycache-remove {
find . -type d -name .mypy_cache -exec rm -r {} + 2>/dev/null || true
}
function ipynbcheckpoints-remove {
find . -type d -name .ipynb_checkpoints -exec rm -r {} + 2>/dev/null || true
}
function pytestcache-remove {
find . -type d -name .pytest_cache -exec rm -r {} + 2>/dev/null || true
}
function build-remove {
rm -rf build/ 2>/dev/null || true
}
################################################################################
# Meta-commands and utilities follow.
function help {
#@ Show help for all available commands (auto-generated)
#@ Category: Meta
printf "%s <command> [args]\n\n" "${0}"
# Extract help information from function comments
# This automatically generates help from #@ comments in functions
local -A categories
local -A descriptions
local -A usages
# Parse all functions and their help comments
while IFS= read -r line; do
if [[ "$line" =~ ^function[[:space:]]+([^[:space:]{}]+) ]]; then
current_func="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^[[:space:]]*#@[[:space:]]*Category:[[:space:]]*(.+) ]]; then
categories["$current_func"]="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^[[:space:]]*#@[[:space:]]*Usage:[[:space:]]*(.+) ]]; then
usages["$current_func"]="${BASH_REMATCH[1]}"
elif [[ "$line" =~ ^[[:space:]]*#@[[:space:]]*(.+) ]] && [[ -z "${descriptions[$current_func]:-}" ]]; then
descriptions["$current_func"]="${BASH_REMATCH[1]}"
fi
done < "$0"
# Group functions by category and display
local -A category_funcs
for func in "${!categories[@]}"; do
local cat="${categories[$func]}"
category_funcs["$cat"]+="$func "
done
# Display in order of preference
local ordered_categories=("Core Development" "Testing/CI" "Package Management" "Docker" "Development Utilities" "Setup/Installation" "Meta")
for category in "${ordered_categories[@]}"; do
if [[ -n "${category_funcs[$category]:-}" ]]; then
echo "${category} Commands:"
for func in ${category_funcs[$category]}; do
local usage="${usages[$func]:-$func}"
local desc="${descriptions[$func]:-No description}"
printf " %-30s %s\n" "$usage" "$desc"
done
echo ""
fi
done
# Handle uncategorized functions
for func in "${!descriptions[@]}"; do
if [[ -z "${categories[$func]:-}" ]]; then
local usage="${usages[$func]:-$func}"
local desc="${descriptions[$func]}"
printf " %-30s %s\n" "$usage" "$desc"
fi
done
}
################################################################################
# Commands end.
# Dispatch to command. A simpler version would be just "$@" (with the quotes!).
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"
# Some dev notes for this script.
#
# The commands *require*:
#
# * The current working directory is the project root.
# * The shell options and globals are set as they are.
#
# Inspired by the following:
# - https://death.andgravity.com/run-sh
# - http://www.oilshell.org/blog/2020/02/good-parts-sketch.html
# - https://www.youtube.com/watch?v=SdmYd5hJISM&t=7s