refactor(python): align all Python components with RespoTemplate-Python best practices - #135
Merged
Merged
Conversation
- tts_service/main.py: pydantic-settings config, structlog logging, asyncio.Lock for XTTS global, run_in_threadpool for all blocking I/O, httpx download with timeout replaces urllib.urlretrieve, configurable CORS (TTS_CORS_ORIGINS env), return type hints on routes - tts_service/requirements.txt: add pydantic-settings + structlog, remove unused pathvalidate - tts_service/Dockerfile: multi-stage build, non-root user (tts:1000), HEALTHCHECK, PYTHONUNBUFFERED/PYTHONDONTWRITEBYTECODE - tts_service/pyproject.toml: ruff + mypy + pytest config (new) - .github/workflows/python-quality.yml: ruff + mypy CI (new) - .github/workflows/codeql-python.yml: Python CodeQL security scan (new) - .github/copilot-instructions.md: Python coding standards (new) - scripts/trellis2_generate.py: fix return type tuple[Path, Path] → tuple[Path, Path, dict] - scripts/trellis2_download_models.py: move import json to top-level
…cript fixes, pre-commit, CI
Copilot created this pull request from a session on behalf of
makr-code
August 1, 2026 09:37
View session
makr-code
marked this pull request as ready for review
August 1, 2026 09:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns
tts_service/andscripts/with the GalaxyQuest Python standards (RespoTemplate-Python).Changes
tts_service/— SoC / OOP restructureconfig.py–pydantic-settingsTTSSettings;TTS_env prefix; noos.getenv()in app codemodels.py–pydantic.BaseModelrequest schema (SynthesiseRequest)cache.py–AudioCachewith atomic writes viaaiofiles; deterministic SHA-256 keyaudio.py–wav_to_mp3helper (ffmpeg viarun_in_threadpool)auth.py–check_secretguard; timing-safe comparisonengines/base.py–TTSEngineProtocol;create_enginefactoryengines/piper.py–PiperEngine; httpx downloads with explicit timeout; SHA-256 keyed model cache; voice-name validation (path-traversal defence);run_in_threadpoolfor all blocking I/Oengines/xtts.py–XTTSEnginestub; fully typedmain.py– slim orchestrator; DI viarequest.app.state; no mutable globals; structlog throughoutDockerfile– multi-stage (builder + runtime); non-root user (useradd+USER);PYTHONUNBUFFERED=1+PYTHONDONTWRITEBYTECODE=1;HEALTHCHECK curl -f /healthscripts/— type safety & robustnesstype | Nonesyntax) on all public functionsexcept Exceptionpathlib.Paththroughout; no raw string pathsToolchain
ruff.toml– project-wide lint/format config.pre-commit-config.yaml– ruff + mypy hooks.github/workflows/python-quality.yml– CI: lint, typecheck, pytest (3 parallel jobs)Tests (25 new)
tests/test_cache.py– 9 tests (key determinism, roundtrip, atomic write)tests/test_config.py– 6 tests (defaults, CORS parsing, env prefix)tests/test_routes.py– 10 tests (health, voices, synthesize, preload)Validation
ruff check✅ ·ruff format --check✅ ·mypy✅ (0 issues on all 12 files)pytest✅ 25/25 passed