From a419167939b155598bbb413263d443d2f1004f50 Mon Sep 17 00:00:00 2001 From: ingo Date: Sat, 21 Nov 2026 00:08:35 +0100 Subject: [PATCH] Cleanup in paths.py and related documents --- doc/API.md | 6 +++++- src/ki18n/paths.py | 14 +++++--------- test/README.md | 2 +- test/test_paths.py | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/API.md b/doc/API.md index 563fc4b..e5998a0 100644 --- a/doc/API.md +++ b/doc/API.md @@ -537,7 +537,11 @@ Directory that contains the bundled application files at runtime: | --- | --- | | Frozen, `sys._MEIPASS` set | `Path(sys._MEIPASS)` | | 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/` folder is bundled there: diff --git a/src/ki18n/paths.py b/src/ki18n/paths.py index 2819f40..1d26c56 100644 --- a/src/ki18n/paths.py +++ b/src/ki18n/paths.py @@ -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 -import logging import os import sys from pathlib import Path -logger = logging.getLogger(__name__) - def is_frozen() -> bool: """True inside a PyInstaller-built executable.""" @@ -16,17 +13,16 @@ def is_frozen() -> bool: 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(): meipass = getattr(sys, "_MEIPASS", None) if meipass: return Path(meipass) - # Onedir builds without _MEIPASS (shouldn't normally happen with - # the bundled spec, but fall back to the executable's directory). + # Onedir builds without _MEIPASS: fall back to the executable's directory. return Path(sys.executable).resolve().parent - # Plain source checkout or a pex zipapp: this file lives at - # /app/runtime_paths.py. + # Not frozen: this file lives at /ki18n/paths.py, so the root is the + # parent of the package directory. return Path(__file__).resolve().parent.parent diff --git a/test/README.md b/test/README.md index 9640535..0548a23 100644 --- a/test/README.md +++ b/test/README.md @@ -26,7 +26,7 @@ Configuration lives in `pyproject.toml` (`[tool.pytest.ini_options]`): | `conftest.py` | Fixtures: `env`, `installed`, `manager`, `log_warnings`, singleton reset | | `support.py` | Example data (`EN`, `DE`, dialog keys) and the `Env` helper class | | `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_discovery.py` | `get_available_languages()`, user and installed resources | | `test_loading.py` | Validation and merging of `strings.json`, regional layers | diff --git a/test/test_paths.py b/test/test_paths.py index 24f2845..607b158 100644 --- a/test/test_paths.py +++ b/test/test_paths.py @@ -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 from pathlib import Path @@ -23,7 +23,7 @@ def test_is_frozen_returns_bool(monkeypatch): 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) assert paths.bundle_root() == Path(paths.__file__).resolve().parent.parent