Cleanup in paths.py and related documents

This commit is contained in:
2026-11-21 00:08:35 +01:00
parent 1575bec4ac
commit a419167939
4 changed files with 13 additions and 13 deletions
+5 -1
View File
@@ -537,7 +537,11 @@ Directory that contains the bundled application files at runtime:
| --- | --- | | --- | --- |
| Frozen, `sys._MEIPASS` set | `Path(sys._MEIPASS)` | | Frozen, `sys._MEIPASS` set | `Path(sys._MEIPASS)` |
| Frozen, no `_MEIPASS` | Directory of `sys.executable` | | Frozen, no `_MEIPASS` | Directory of `sys.executable` |
| Source checkout | Parent of the `ki18n` package directory | | Not frozen | Parent of the `ki18n` package directory |
When `ki18n` is installed as a package, "not frozen" means the directory that
contains the package (for example `site-packages`), not your application
directory. In that case pass `project_root` explicitly.
For a frozen application, pass `bundle_root()` as `project_root` if the `i18n/` For a frozen application, pass `bundle_root()` as `project_root` if the `i18n/`
folder is bundled there: folder is bundled there:
+5 -9
View File
@@ -1,14 +1,11 @@
"""Standard paths of the application (and transfer of data from the previous version ``vorta-tui``).""" """Standard paths: PyInstaller bundle detection and per-user data directories."""
from __future__ import annotations from __future__ import annotations
import logging
import os import os
import sys import sys
from pathlib import Path from pathlib import Path
logger = logging.getLogger(__name__)
def is_frozen() -> bool: def is_frozen() -> bool:
"""True inside a PyInstaller-built executable.""" """True inside a PyInstaller-built executable."""
@@ -16,17 +13,16 @@ def is_frozen() -> bool:
def bundle_root() -> Path: def bundle_root() -> Path:
"""Directory that contains ``i18n/`` and ``core`` at runtime.""" """Directory that contains the bundled application files (e.g. ``i18n/``) at runtime."""
if is_frozen(): if is_frozen():
meipass = getattr(sys, "_MEIPASS", None) meipass = getattr(sys, "_MEIPASS", None)
if meipass: if meipass:
return Path(meipass) return Path(meipass)
# Onedir builds without _MEIPASS (shouldn't normally happen with # Onedir builds without _MEIPASS: fall back to the executable's directory.
# the bundled spec, but fall back to the executable's directory).
return Path(sys.executable).resolve().parent return Path(sys.executable).resolve().parent
# Plain source checkout or a pex zipapp: this file lives at # Not frozen: this file lives at <root>/ki18n/paths.py, so the root is the
# <project_root>/app/runtime_paths.py. # parent of the package directory.
return Path(__file__).resolve().parent.parent return Path(__file__).resolve().parent.parent
+1 -1
View File
@@ -26,7 +26,7 @@ Configuration lives in `pyproject.toml` (`[tool.pytest.ini_options]`):
| `conftest.py` | Fixtures: `env`, `installed`, `manager`, `log_warnings`, singleton reset | | `conftest.py` | Fixtures: `env`, `installed`, `manager`, `log_warnings`, singleton reset |
| `support.py` | Example data (`EN`, `DE`, dialog keys) and the `Env` helper class | | `support.py` | Example data (`EN`, `DE`, dialog keys) and the `Env` helper class |
| `test_normalize.py` | Language ID normalization, fallback chains | | `test_normalize.py` | Language ID normalization, fallback chains |
| `test_paths.py` | `ki18n.paths` (PyInstaller / source checkout) | | `test_paths.py` | `ki18n.paths` (PyInstaller / source checkout, per-user data directories) |
| `test_construction.py` | Constructor, singleton, `project_root`/`local_root`, data directories | | `test_construction.py` | Constructor, singleton, `project_root`/`local_root`, data directories |
| `test_discovery.py` | `get_available_languages()`, user and installed resources | | `test_discovery.py` | `get_available_languages()`, user and installed resources |
| `test_loading.py` | Validation and merging of `strings.json`, regional layers | | `test_loading.py` | Validation and merging of `strings.json`, regional layers |
+2 -2
View File
@@ -1,4 +1,4 @@
"""Tests for ``ki18n.paths`` (PyInstaller / source checkout detection, data directories).""" """Tests for ``ki18n.paths`` (PyInstaller bundle detection, per-user data directories)."""
import sys import sys
from pathlib import Path from pathlib import Path
@@ -23,7 +23,7 @@ def test_is_frozen_returns_bool(monkeypatch):
assert paths.is_frozen() is True assert paths.is_frozen() is True
def test_source_checkout_uses_parent_of_package_directory(monkeypatch): def test_not_frozen_uses_parent_of_package_directory(monkeypatch):
monkeypatch.setattr(sys, "frozen", False, raising=False) monkeypatch.setattr(sys, "frozen", False, raising=False)
assert paths.bundle_root() == Path(paths.__file__).resolve().parent.parent assert paths.bundle_root() == Path(paths.__file__).resolve().parent.parent