Coverage for src / ezqt_app / utils / runtime_paths.py: 100.00%
15 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 07:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-26 07:07 +0000
1# ///////////////////////////////////////////////////////////////
2# UTILS.RUNTIME_PATHS - Runtime path helpers
3# Project: ezqt_app
4# ///////////////////////////////////////////////////////////////
6# ruff: noqa: I001
8"""Low-level path helpers used at runtime."""
10from __future__ import annotations
12# ///////////////////////////////////////////////////////////////
13# IMPORTS
14# ///////////////////////////////////////////////////////////////
15# Standard library imports
16import sys
17from pathlib import Path
18from typing import Final
20# ///////////////////////////////////////////////////////////////
21# CONSTANTS
22# ///////////////////////////////////////////////////////////////
23APP_PATH: Final[Path] = Path(
24 getattr(sys, "_MEIPASS", Path(sys.argv[0]).resolve().parent)
25)
27# ///////////////////////////////////////////////////////////////
28# MUTABLE BIN PATH
29# ///////////////////////////////////////////////////////////////
30_bin_path: Path | None = None
31_bin_path_user_set: bool = False
34def get_bin_path() -> Path:
35 """Return the active bin directory.
37 Defaults to ``APP_PATH / "bin"`` unless overridden by :func:`set_bin_path`.
38 """
39 return _bin_path if _bin_path is not None else APP_PATH / "bin"
42def set_bin_path(path: Path) -> None:
43 """Override the bin directory used by all runtime services.
45 Call this during bootstrap (before any service loads resources) when the
46 consuming application places its assets in a non-default folder.
48 Args:
49 path: Absolute path to the bin directory (e.g. ``project_root / "binaries"``).
50 """
51 global _bin_path, _bin_path_user_set # noqa: PLW0603
52 _bin_path = path
53 _bin_path_user_set = True
56def _sync_bin_path_from_root(path: Path) -> None: # pyright: ignore[reportUnusedFunction]
57 """Update bin path derived from the project root, unless user-set.
59 Called internally by ``ConfigService.set_project_root()`` so that services
60 relying on :func:`get_bin_path` stay in sync without going through bootstrap.
61 No-op when the user has already called :func:`set_bin_path` explicitly.
62 """
63 global _bin_path # noqa: PLW0603
64 if not _bin_path_user_set:
65 _bin_path = path