-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-python.sh
More file actions
71 lines (57 loc) · 1.9 KB
/
Copy pathbuild-python.sh
File metadata and controls
71 lines (57 loc) · 1.9 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
#!/usr/bin/env bash
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
if [[ -x "$PROJECT_ROOT/.venv/bin/python" ]]; then
PYTHON_EXE="$PROJECT_ROOT/.venv/bin/python"
else
PYTHON_EXE="${PYTHON_BIN:-python3}"
fi
if ! "$PYTHON_EXE" -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('PyInstaller') else 1)"; then
echo "PyInstaller not found. Run 'python -m pip install pyinstaller' before building." >&2
exit 1
fi
DIST_PATH="$PROJECT_ROOT/build/python-dist"
WORK_PATH="$PROJECT_ROOT/build/pyinstaller/work"
SPEC_PATH="$PROJECT_ROOT/build/pyinstaller/spec"
HOOKS_PATH="$PROJECT_ROOT/scripts/pyinstaller-hooks"
TARGET_ARCH="${PYINSTALLER_TARGET_ARCH:-}"
rm -rf "$DIST_PATH" "$PROJECT_ROOT/build/pyinstaller"
mkdir -p "$DIST_PATH" "$WORK_PATH" "$SPEC_PATH"
COMMON_ARGS=(
-m PyInstaller
--noconfirm
--clean
--distpath "$DIST_PATH"
--workpath "$WORK_PATH"
--specpath "$SPEC_PATH"
--additional-hooks-dir "$HOOKS_PATH"
)
CUDA_ARGS=()
has_python_module() {
"$PYTHON_EXE" -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('$1') else 1)" >/dev/null 2>&1
}
for module in nvidia.cublas nvidia.cudnn nvidia.cuda_runtime; do
if has_python_module "$module"; then
CUDA_ARGS+=(--collect-all "$module")
fi
done
if [[ "$OSTYPE" == darwin* && -n "$TARGET_ARCH" ]]; then
COMMON_ARGS+=(--target-arch "$TARGET_ARCH")
fi
DICTATION_ARGS=("${COMMON_ARGS[@]}")
if ((${#CUDA_ARGS[@]} > 0)); then
DICTATION_ARGS+=("${CUDA_ARGS[@]}")
fi
"$PYTHON_EXE" "${DICTATION_ARGS[@]}" \
--name dictation_service \
--collect-all faster_whisper \
--collect-all ctranslate2 \
--collect-all tokenizers \
--collect-all huggingface_hub \
--collect-all sounddevice \
python/dictation_service.py
"$PYTHON_EXE" "${COMMON_ARGS[@]}" \
--name hotkey_listener \
--collect-submodules pynput \
python/hotkey_listener.py
echo "Python workers built in $DIST_PATH"