diff --git a/python/common.py b/python/common.py index 3703ca2..f14d404 100644 --- a/python/common.py +++ b/python/common.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging from datetime import UTC, datetime +from pathlib import Path from subprocess import PIPE, Popen from python.logging_config import configure_logger as _configure_logger @@ -11,6 +12,11 @@ from python.logging_config import configure_logger as _configure_logger logger = logging.getLogger(__name__) +def get_repo_dir() -> Path: + """Return the repository root directory.""" + return Path(__file__).resolve().parents[1] + + def configure_logger(level: str = "INFO") -> None: """Configure the logger.""" _configure_logger(level) diff --git a/python/tools/whisper/transcribe.py b/python/tools/whisper/transcribe.py index 2003696..cf4aae0 100644 --- a/python/tools/whisper/transcribe.py +++ b/python/tools/whisper/transcribe.py @@ -14,7 +14,7 @@ from typing import Annotated import typer -from python.common import configure_logger +from python.common import configure_logger, get_repo_dir logger = logging.getLogger(__name__) @@ -24,7 +24,7 @@ class Config: image_tag = "whisper-transcribe:latest" model_volume = "whisper-models" - repo_root = Path(__file__).resolve().parents[3] + repo_root = get_repo_dir() dockerfile = Path(__file__).resolve().parent / "Dockerfile" huggingface_cache = "/root/.cache/huggingface" diff --git a/tests/test_common.py b/tests/test_common.py index ca86873..2ce9799 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -2,7 +2,14 @@ from __future__ import annotations -from python.common import bash_wrapper, utcnow +from python.common import bash_wrapper, get_repo_dir, utcnow + + +def test_get_repo_dir() -> None: + """test_get_repo_dir.""" + repo_dir = get_repo_dir() + assert (repo_dir / "pyproject.toml").is_file() + assert (repo_dir / "python" / "common.py").is_file() def test_utcnow() -> None: