tts-kokoro engine underway
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2025-2026 Renato Xavier da Silveira Rosa
|
||||
# See [LICENSE](./LICENSE) or [BSD-3-Clause-Clear](https://spdx.org/licenses/BSD-3-Clause-Clear.html)
|
||||
# Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
||||
"""Utilities for running vendored EPUB->TTS repositories in isolated venvs."""
|
||||
|
||||
import subprocess
|
||||
import shutil
|
||||
import sys
|
||||
import venv
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from . import log, PathLike
|
||||
|
||||
def get_vendor_root() -> Path:
|
||||
return Path(__file__).resolve().parents[1] / "vendor"
|
||||
|
||||
|
||||
def get_repo_path(repo_name: str) -> Path:
|
||||
repo_path = get_vendor_root() / repo_name
|
||||
if not repo_path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Vendored repository '{repo_name}' not found under {get_vendor_root()}"
|
||||
)
|
||||
return repo_path
|
||||
|
||||
|
||||
def get_venv_path(repo_name: str) -> Path:
|
||||
return get_repo_path(repo_name) / ".venv"
|
||||
|
||||
|
||||
def get_venv_python(repo_name: str) -> Path:
|
||||
venv_path = get_venv_path(repo_name)
|
||||
python_executable = (
|
||||
venv_path / "Scripts" / "python.exe"
|
||||
if sys.platform == "win32"
|
||||
else venv_path / "bin" / "python"
|
||||
)
|
||||
if not python_executable.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Python executable not found in virtualenv at {python_executable}"
|
||||
)
|
||||
return python_executable
|
||||
|
||||
|
||||
def ensure_venv(repo_name: str) -> Path:
|
||||
repo_path = get_repo_path(repo_name)
|
||||
venv_path = get_venv_path(repo_name)
|
||||
if not venv_path.exists():
|
||||
venv.EnvBuilder(with_pip=True).create(venv_path)
|
||||
python_executable = get_venv_python(repo_name)
|
||||
subprocess.run(
|
||||
[str(python_executable), "-m", "pip", "install", "-e", str(repo_path)],
|
||||
check=True,
|
||||
)
|
||||
return get_venv_python(repo_name)
|
||||
|
||||
|
||||
def build_run_command(
|
||||
repo_name: str,
|
||||
# backend_cmd: str = None,
|
||||
) -> str:
|
||||
return str(ensure_venv(repo_name))
|
||||
# if not backend_cmd:
|
||||
# return str(ensure_venv(repo_name))
|
||||
# ensure_venv(repo_name)
|
||||
# venv_path = get_venv_path(repo_name)
|
||||
# return (
|
||||
# str( venv_path / "Scripts" / f"{backend_cmd}.exe")
|
||||
# if sys.platform == "win32"
|
||||
# else str(venv_path / "bin" / backend_cmd)
|
||||
# )
|
||||
|
||||
|
||||
|
||||
def check_env(self, which=None):
|
||||
if not which:
|
||||
return None
|
||||
if isinstance(which, str):
|
||||
if " " in which:
|
||||
which = which.split()
|
||||
which = [which]
|
||||
for bin in which:
|
||||
p = shutil.which(bin)
|
||||
if not p:
|
||||
log(f"{bin} is either NOT installed or "
|
||||
"NOT in your system PATH.")
|
||||
return False
|
||||
else:
|
||||
log(f"{bin} found at: {p}")
|
||||
return True
|
||||
Reference in New Issue
Block a user