-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop
More file actions
executable file
·160 lines (144 loc) · 4.09 KB
/
pop
File metadata and controls
executable file
·160 lines (144 loc) · 4.09 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
#!/bin/bash
#
# pop - Project Operation
#
# A simple project operation execution script for environments lacking "make",
# "just", "pip", "uv", and "poetry" and where installing Python dependencies at
# the system level is undesirable. This script manages a local virtualenv and
# provides common project operations.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/.venv"
PYTHON="${VENV_DIR}/bin/python"
PROG="$SCRIPT_DIR/serialtest.py"
# Exit codes
EXIT_OK=0
EXIT_USAGE=2 # Missing argument or invalid operation
EXIT_SETUP_FAILED=4 # Setup or dependency installation failed
EXIT_RUN_FAILED=5 # Python script or test execution failed
usage() {
cat <<EOF
Usage: $(basename "$0") <operation> [args...]
Operations:
setup Create virtualenv and install dependencies
clean Remove cache directories (__pycache__, .pytest_cache, etc.)
distclean Remove virtualenv and all cache directories
test Run all tests (unit + integration)
test-unit Run unit tests only (fast, no socat required)
test-integration Run integration tests only (requires Linux + socat)
run [args] Run serial test (args passed to serialtest.py)
help Show this help message
Examples:
./pop run -d /dev/ttyAMA4 -r server # Run as server
./pop run -d /dev/ttyUSB0 -r client -n 100 # Run as client with msg count
Run './pop run --help' for run options (device, role, baudrate, etc.)
EOF
}
cmd_setup() {
echo "Creating virtualenv in $VENV_DIR..."
if ! python3 -m venv "$VENV_DIR"; then
echo "Error: Failed to create virtualenv." >&2
exit $EXIT_SETUP_FAILED
fi
echo "Installing dependencies..."
if ! "$VENV_DIR/bin/pip" install --quiet --upgrade pip; then
echo "Error: Failed to upgrade pip." >&2
exit $EXIT_SETUP_FAILED
fi
if ! "$VENV_DIR/bin/pip" install --quiet -r "$SCRIPT_DIR/requirements.txt"; then
echo "Error: Failed to install requirements." >&2
exit $EXIT_SETUP_FAILED
fi
echo "Setup complete."
}
ensure_setup() {
if [[ ! -x "$PYTHON" ]]; then
echo "Virtualenv not found. Running setup..."
cmd_setup
fi
}
cmd_clean() {
echo "Removing cache directories..."
rm -rf "$SCRIPT_DIR"/__pycache__
rm -rf "$SCRIPT_DIR"/*/__pycache__
rm -rf "$SCRIPT_DIR"/.mypy_cache
rm -rf "$SCRIPT_DIR"/.pytest_cache
rm -rf "$SCRIPT_DIR"/.ruff_cache
echo "Cache clean complete."
}
cmd_distclean() {
cmd_clean
echo "Removing virtualenv..."
rm -rf "$VENV_DIR"
echo "Distclean complete."
}
cmd_test() {
ensure_setup
echo "Running tests..."
# Run all tests with pytest; integration tests requiring Linux will be
# automatically skipped on non-Linux platforms via @pytest.mark.skipif
if ! "$PYTHON" -m pytest "$SCRIPT_DIR/test" -v; then
echo "Error: Tests failed." >&2
exit $EXIT_RUN_FAILED
fi
}
cmd_test_unit() {
ensure_setup
echo "Running unit tests..."
if ! "$PYTHON" -m pytest "$SCRIPT_DIR/test" -m unit -v; then
echo "Error: Unit tests failed." >&2
exit $EXIT_RUN_FAILED
fi
}
cmd_test_integration() {
ensure_setup
echo "Running integration tests..."
if ! "$PYTHON" -m pytest "$SCRIPT_DIR/test" -m integration -v; then
echo "Error: Integration tests failed." >&2
exit $EXIT_RUN_FAILED
fi
}
cmd_run() {
ensure_setup
if ! "$PYTHON" "$PROG" "$@"; then
echo "Error: Run failed." >&2
exit $EXIT_RUN_FAILED
fi
}
if [[ $# -lt 1 ]]; then
usage
exit $EXIT_USAGE
fi
case "$1" in
setup)
cmd_setup
;;
clean)
cmd_clean
;;
distclean)
cmd_distclean
;;
test)
cmd_test
;;
test-unit)
cmd_test_unit
;;
test-integration)
cmd_test_integration
;;
run)
shift
cmd_run "$@"
;;
help|--help|-h)
usage
;;
*)
echo "Error: Unknown operation '$1'" >&2
usage
exit $EXIT_USAGE
;;
esac