Files
VoiceStudio/backend/hooks/pyi_rth_numpy_compat.py
T
debpalashandClaude Opus 4.7 994c6cf065 feat(backend): setup wizard router, translation engines, export options, client-disconnect handling
- Add setup router (backend/api/routers/setup.py) for first-run wizard:
  system checks, engine probes, model downloads with progress
- Add translation engines service with pluggable backends
- Add utils/hf_progress for HuggingFace download progress streaming
- Add PyInstaller runtime hooks (numpy compat, torch compiler disable)
- Global exception handler short-circuits h11 LocalProtocolError and
  Starlette ClientDisconnect with HTTP 499 to silence noisy stack traces
  when users scrub or cancel video mid-stream
- /dub/download-mp3 accepts bitrate query param (clamped 64–320kbps)
- Refactor ASR/TTS backends, dub pipeline, engine management
- Update backend.spec for PyInstaller packaging
- Bump pyproject version to 0.2.0; refresh uv.lock

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 17:49:04 +05:30

29 lines
1.1 KiB
Python

"""Numpy compatibility shim for PyInstaller.
Two things we have to guarantee in a frozen build:
1. `numpy` gets imported before anything that monkey-touches its C API
(scipy, torch, torchaudio) so the extension loader runs in a clean
state and we don't hit "module compiled against API version X but
this version of numpy is Y" surprises.
2. NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is left at its default. Some
frozen builds end up with it unset because PyInstaller strips certain
env-based defaults — explicitly mirror numpy's own default so
downstream libs don't disable fast paths by accident.
This hook runs BEFORE the main script via `runtime_hooks=[...]` in the
spec, so the import order is deterministic regardless of which library
the user's code touches first.
"""
import os
os.environ.setdefault("NUMPY_EXPERIMENTAL_ARRAY_FUNCTION", "1")
try:
import numpy # noqa: F401 (side-effect import: primes the C extension)
except ImportError:
# Let the main app fail loudly with its own error message rather
# than crashing the runtime hook itself.
pass