Skip to content

refactor(python): align all Python components with RespoTemplate-Python best practices - #135

Merged
makr-code merged 2 commits into
developfrom
copilot/check-ai-and-template-best-practices
Aug 1, 2026
Merged

refactor(python): align all Python components with RespoTemplate-Python best practices#135
makr-code merged 2 commits into
developfrom
copilot/check-ai-and-template-best-practices

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Aligns tts_service/ and scripts/ with the GalaxyQuest Python standards (RespoTemplate-Python).

Changes

tts_service/ — SoC / OOP restructure

  • config.pypydantic-settings TTSSettings; TTS_ env prefix; no os.getenv() in app code
  • models.pypydantic.BaseModel request schema (SynthesiseRequest)
  • cache.pyAudioCache with atomic writes via aiofiles; deterministic SHA-256 key
  • audio.pywav_to_mp3 helper (ffmpeg via run_in_threadpool)
  • auth.pycheck_secret guard; timing-safe comparison
  • engines/base.pyTTSEngine Protocol; create_engine factory
  • engines/piper.pyPiperEngine; httpx downloads with explicit timeout; SHA-256 keyed model cache; voice-name validation (path-traversal defence); run_in_threadpool for all blocking I/O
  • engines/xtts.pyXTTSEngine stub; fully typed
  • main.py – slim orchestrator; DI via request.app.state; no mutable globals; structlog throughout
  • Dockerfile – multi-stage (builder + runtime); non-root user (useradd + USER); PYTHONUNBUFFERED=1 + PYTHONDONTWRITEBYTECODE=1; HEALTHCHECK curl -f /health

scripts/ — type safety & robustness

  • Full type hints (type | None syntax) on all public functions
  • Specific exception types; no bare except Exception
  • pathlib.Path throughout; no raw string paths

Toolchain

  • 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
  • CodeQL ✅ 0 findings

Copilot AI added 2 commits August 1, 2026 08:08
- 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
Copilot AI requested a review from makr-code August 1, 2026 09:37
@makr-code
makr-code marked this pull request as ready for review August 1, 2026 09:51
@makr-code
makr-code merged commit bd6ac19 into develop Aug 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants