tenseleyflow/sway / 36d3f1c

Browse files

probes/_null_cache: SWAY_NULL_CACHE_DIR override for sway unpack (S26 X3-P2)

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
36d3f1c8eec55ff7abc9e03cb1821e2d4a87cf78
Parents
5e1ff5b
Tree
39d80be

1 changed file

StatusFile+-
M src/dlm_sway/probes/_null_cache.py 21 2
src/dlm_sway/probes/_null_cache.pymodified
@@ -25,10 +25,29 @@ from typing import Any
2525
 #: / CI tests that want to prove calibration actually runs).
2626
 _ENV_DISABLE = "SWAY_DISABLE_NULL_CACHE"
2727
 
28
+#: S26 — env knob pointing at a custom null-cache directory. Used by
29
+#: ``sway unpack`` to redirect lookups at a packed cache shipped in
30
+#: a ``.swaypack.tar.gz`` instead of the user's home cache. Path is
31
+#: used verbatim (no ``dlm-sway/null-stats`` suffix) so packs can
32
+#: ship a flat directory of ``<key>.json`` files.
33
+_ENV_OVERRIDE = "SWAY_NULL_CACHE_DIR"
34
+
2835
 
2936
 def _cache_root() -> Path:
30
-    """Root directory for cached null stats. Honors ``$XDG_CACHE_HOME``
31
-    when set; otherwise falls back to ``~/.dlm-sway/null-stats``."""
37
+    """Root directory for cached null stats.
38
+
39
+    Resolution order:
40
+
41
+    1. ``$SWAY_NULL_CACHE_DIR`` if set — used verbatim. ``sway unpack``
42
+       points this at the unpacked cache directory inside a swaypack
43
+       so subsequent ``sway run`` calls hit the packed stats instead
44
+       of the user's home cache (S26).
45
+    2. ``$XDG_CACHE_HOME/dlm-sway/null-stats`` if XDG is set.
46
+    3. ``~/.dlm-sway/null-stats`` otherwise.
47
+    """
48
+    override = os.environ.get(_ENV_OVERRIDE)
49
+    if override:
50
+        return Path(override).expanduser()
3251
     xdg = os.environ.get("XDG_CACHE_HOME")
3352
     if xdg:
3453
         return Path(xdg).expanduser() / "dlm-sway" / "null-stats"