aeat.core._config_state_root module¶
Installed-vs-checkout detection and the platform user-data storage root.
The central settings facade (Settings) roots the
encrypted profile store at aeat_local_storage_root, from which the token,
log, secret, blob and audit roots derive. Historically that root defaulted to
PROJECT_ROOT / "var" / "storage", which is correct for a source checkout
but wrong for an installed distribution: under a wheel it resolves inside the
virtualenv, and under uvx inside uv’s ephemeral cache, where a cache prune
could silently destroy the taxpayer’s encrypted store.
This module owns the two decisions that fix that defect without disturbing the
dev loop: whether the process runs from a source checkout or an installed
distribution (detect_run_mode()), and where the platform user-data base
lives per operating system (platform_user_data_root()). A checkout keeps
the PROJECT_ROOT / "var" / "storage" default; an installed run lands under
the platform user-data directory (%LOCALAPPDATA% on Windows,
$XDG_DATA_HOME with the ~/.local/share fallback on Linux,
~/Library/Application Support on macOS).
Every input the resolution reads — the project-root candidate, the platform
string, the environment mapping, and the home directory — is captured in the
frozen StateRootInputs seam so the detection is deterministic and
testable without mutating the ambient process. default_storage_root() is
the live entry point Settings binds as its
aeat_local_storage_root default factory.
See also
SettingsCentral settings aggregate whose storage-root default is resolved here.
PROJECT_ROOTCheckout-root anchor mirrored when source-tree defaults are preserved.
StateRootInputsFrozen seam that captures every environmental input used by resolution.
detect_run_mode()Checkout-versus-installed classifier used before selecting a root.
resolve_state_root()Pure resolver that returns the effective storage root.
default_storage_root()Live default factory bound into the settings model.
- class RunMode(*values)[source]¶
Bases:
StrEnumWhether the process runs from a source checkout or an installed build.
detect_run_mode()returns a member;resolve_state_root()branches on it to pick the checkoutvar/storagedefault or the platform user-data directory.- CHECKOUT¶
- INSTALLED¶
- class StateRootInputs(**data)[source]¶
Bases:
BaseModelInjectable, frozen seam for state-root resolution.
Capturing every environmental input as an explicit field makes both
detect_run_mode()andplatform_user_data_root()pure functions of their argument, so tests construct aninstalledorcheckoutcontext deterministically rather than mutatingos.environor patchingsys.platform.- project_root_candidate: Path¶
- platform: str¶
- environ: dict[str, str]¶
- home: Path¶
- class StateRootResolution(**data)[source]¶
Bases:
BaseModelTyped outcome of resolving the storage state root.
Carries the decided
RunMode, the project-root candidate it was decided from, the platform user-data base, and the effectivestorage_rootthatSettingsshould defaultaeat_local_storage_rootto.- Parameters:
- run_mode: RunMode¶
- project_root: Path¶
- platform_user_data_root: Path¶
- storage_root: Path¶
- live_state_root_inputs()[source]¶
Capture the running process’s state-root inputs.
Snapshots the module-derived project-root candidate,
platform, a copy ofos.environ, and the user’s home directory into a frozenStateRootInputsforresolve_state_root().- Return type:
- detect_run_mode(inputs)[source]¶
Classify the run as a source checkout or an installed distribution.
A source checkout carries the repository markers at its project root: a
pyproject.tomlfile and a.gitentry (a directory in a normal clone, a pointer file inside a git worktree — so presence, not directory-ness, is the test). An installed wheel resolves the candidate undersite-packageswhere neither marker exists, so the absence of either marker classifies the run as installed.- Return type:
- Parameters:
inputs (StateRootInputs)
- platform_user_data_root(inputs)[source]¶
Resolve the
aeatplatform user-data directory for the given inputs.Windows resolves under
%LOCALAPPDATA%(~/AppData/Localwhen the variable is unset or not absolute); macOS under~/Library/Application Support; every other platform under$XDG_DATA_HOME(~/.local/sharewhen unset or not absolute). Theaeatapplication directory name is appended to the resolved base.- Return type:
Path- Parameters:
inputs (StateRootInputs)
- resolve_state_root(inputs)[source]¶
Resolve the effective storage state root for the given inputs.
A checkout keeps the historical
PROJECT_ROOT / "var" / "storage"default; an installed run lands at<platform-user-data>/aeat/storageso the encrypted store never resolves inside a virtualenv or uv cache.- Return type:
- Parameters:
inputs (StateRootInputs)
- default_storage_root()[source]¶
Return the
aeat_local_storage_rootdefault for the live process.Bound as the
Settingsaeat_local_storage_rootdefault factory: a checkout resolves toPROJECT_ROOT / "var" / "storage"(unchanged), an installed run to the platform user-data storage directory.- Return type:
Path