mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-14 22:31:00 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
102 lines
4.1 KiB
Bash
Executable File
102 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Virtualenv setup and the model download.
|
|
#
|
|
# Sourced by transcribe.sh; split out to keep it under the 250-line
|
|
# cap. Sourced rather than run, so it inherits the caller's strict mode
|
|
# and the variables defined above the source line.
|
|
|
|
setup_venv() {
|
|
if [[ ! -d $VENV_DIR ]]; then
|
|
log "Creating venv at $VENV_DIR"
|
|
python3 -m venv "$VENV_DIR"
|
|
fi
|
|
# shellcheck disable=SC1091
|
|
source "$VENV_DIR/bin/activate"
|
|
if [[ $OFFLINE -eq 0 ]]; then
|
|
python -m pip install --upgrade pip wheel setuptools
|
|
fi
|
|
}
|
|
|
|
install_python_deps() {
|
|
# Install deps; if NVIDIA GPU is present, prefer CUDA-capable stack (cu12)
|
|
local has_nvidia_flag="${1:-0}"
|
|
log "Installing faster-whisper and dependencies"
|
|
export PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
export PIP_DEFAULT_TIMEOUT=${PIP_DEFAULT_TIMEOUT:-20}
|
|
if [[ $OFFLINE -eq 1 ]]; then
|
|
# Offline: do not install, just verify modules
|
|
if ! python "$PY_HELPERS" check-faster-whisper; then
|
|
exit 7
|
|
fi
|
|
# If diarization requested offline, check for its deps too (warn-only)
|
|
if [[ ${FW_DIARIZE:-} == "1" ]]; then
|
|
python "$PY_HELPERS" check-diarization || true
|
|
fi
|
|
return 0
|
|
fi
|
|
if [[ $has_nvidia_flag -eq 1 ]]; then
|
|
# If ctranslate2 is not installed, attempt CUDA-enabled wheel (with fallback)
|
|
if ! "$VENV_DIR/bin/python" "$PY_HELPERS" check-ctranslate2 2> /dev/null; then
|
|
log "Installing CUDA-enabled CTranslate2 (cu12 wheel)"
|
|
python -m pip install --progress-bar on --retries 1 --upgrade "ctranslate2<5,>=4.0" --extra-index-url https://download.opennmt.net/ctranslate2/cu12 ||
|
|
log "Warning: could not reach cu12 wheel index; will proceed with available ctranslate2"
|
|
fi
|
|
# Ensure NVIDIA CUDA 12 runtime libs are available inside the venv
|
|
python -m pip install --progress-bar on --retries 1 --upgrade nvidia-cublas-cu12 nvidia-cuda-runtime-cu12 nvidia-cudnn-cu12 ||
|
|
log "Warning: failed to install NVIDIA cu12 runtime libs via pip"
|
|
fi
|
|
python -m pip install --progress-bar on --retries 1 --upgrade faster-whisper ffmpeg-python
|
|
|
|
# If diarization requested and online, install its Python deps best-effort
|
|
if [[ ${FW_DIARIZE:-} == "1" ]]; then
|
|
python -m pip install --progress-bar on --retries 1 --upgrade soundfile speechbrain ||
|
|
log "Warning: failed to install soundfile/speechbrain"
|
|
# Torch and torchaudio CPU wheels (force to avoid mismatched CUDA builds)
|
|
python -m pip install --progress-bar on --retries 1 --upgrade --force-reinstall --index-url https://download.pytorch.org/whl/cpu torch torchaudio ||
|
|
log "Warning: failed to install torch/torchaudio CPU wheels"
|
|
fi
|
|
python "$PY_HELPERS" deps-installed
|
|
}
|
|
|
|
ensure_runner() {
|
|
if [[ ! -f $PY_RUNNER ]]; then
|
|
echo "Runner not found: $PY_RUNNER" >&2
|
|
exit 3
|
|
fi
|
|
}
|
|
|
|
generate_test_audio() {
|
|
local tmpwav
|
|
tmpwav="${PROJECT_DIR}/test_fw.wav"
|
|
if command -v espeak-ng > /dev/null 2>&1; then
|
|
log "Generating test audio via espeak-ng -> $tmpwav" >&2
|
|
espeak-ng -w "$tmpwav" "This is a quick test of faster whisper transcription." > /dev/null 2>&1 || true
|
|
fi
|
|
# If espeak-ng failed or not present, try espeak
|
|
if [[ ! -s $tmpwav ]] && command -v espeak > /dev/null 2>&1; then
|
|
log "espeak-ng unavailable or failed; trying espeak -> $tmpwav" >&2
|
|
espeak -w "$tmpwav" "This is a quick test of faster whisper transcription." > /dev/null 2>&1 || true
|
|
fi
|
|
# Fallback: generate tone via Python stdlib (no external deps)
|
|
if [[ ! -s $tmpwav ]]; then
|
|
log "Generating 3s 1kHz WAV via Python stdlib -> $tmpwav" >&2
|
|
python3 "$PY_HELPERS" generate-wav --file "$tmpwav" || true
|
|
fi
|
|
# Final fallback: tone via ffmpeg
|
|
if [[ ! -s $tmpwav ]]; then
|
|
log "Creating a 3s sine tone WAV via ffmpeg -> $tmpwav" >&2
|
|
ffmpeg -f lavfi -i sine=frequency=1000:duration=3 -ar 16000 -ac 1 -f wav -y "$tmpwav" > /dev/null 2>&1 || true
|
|
fi
|
|
echo "$tmpwav"
|
|
}
|
|
|
|
prepare_model() {
|
|
# Download a model for offline use into MODEL_DIR
|
|
local name="$1"
|
|
mkdir -p "$MODEL_DIR"
|
|
# shellcheck disable=SC1091
|
|
source "$VENV_DIR/bin/activate"
|
|
log "Preparing model '$name' into $MODEL_DIR"
|
|
python "$PY_HELPERS" prepare-model --model "$name" --model-dir "$MODEL_DIR"
|
|
}
|