refactor: move expand/expand_dests to entry methods

This commit is contained in:
2 * r + 2 * t
2026-06-17 00:58:06 +10:00
parent 63a6e5a6f2
commit 0980986ed4
2 changed files with 24 additions and 22 deletions
+3 -3
View File
@@ -6,7 +6,7 @@ from argparse import Namespace
from pathlib import Path from pathlib import Path
from caelestia.utils.dots.deployer import Deployer from caelestia.utils.dots.deployer import Deployer
from caelestia.utils.dots.manifest import ComponentError, Manifest, ManifestError, expand, expand_dests from caelestia.utils.dots.manifest import ComponentError, Manifest, ManifestError
from caelestia.utils.dots.packages import DEFAULT_AUR_HELPER, PackageInstaller from caelestia.utils.dots.packages import DEFAULT_AUR_HELPER, PackageInstaller
from caelestia.utils.dots.source import DotsSource, SourceError from caelestia.utils.dots.source import DotsSource, SourceError
from caelestia.utils.dots.state import DotsState from caelestia.utils.dots.state import DotsState
@@ -180,12 +180,12 @@ class Command:
log("Installing configs...") log("Installing configs...")
deployer = Deployer() deployer = Deployer()
for entry in manifest.enabled_entries(): for entry in manifest.enabled_entries():
src = source.working_path(expand(entry.src)) src = source.working_path(entry.expanded_src())
if not src.exists(): if not src.exists():
warn(f"missing in source, skipping: {entry.src}") warn(f"missing in source, skipping: {entry.src}")
continue continue
dests = expand_dests(entry.dest) dests = entry.expanded_dests()
if not dests: if not dests:
warn(f"dest glob matched nothing, skipping: {entry.dest}") warn(f"dest glob matched nothing, skipping: {entry.dest}")
continue continue
+12 -10
View File
@@ -25,21 +25,29 @@ class ComponentError(Exception):
"""Raised when component flags are invalid or contradictory.""" """Raised when component flags are invalid or contradictory."""
def expand(text: str) -> Path: def _expand(text: str) -> Path:
"""Expand $VAR/${VAR} env vars (with XDG defaults) and ~ in a path.""" """Expand $VAR/${VAR} env vars (with XDG defaults) and ~ in a path."""
env = {**_XDG_DEFAULTS, **os.environ} env = {**_XDG_DEFAULTS, **os.environ}
return Path(Template(text).safe_substitute(env)).expanduser() return Path(Template(text).safe_substitute(env)).expanduser()
def expand_dests(dest: str) -> list[Path]: @dataclass(frozen=True)
"""Expand globs within a dest path. class ManifestEntry:
src: str
dest: str
def expanded_src(self) -> Path:
return _expand(self.src)
def expanded_dests(self) -> list[Path]:
"""The dest path with globs expanded.
Globs from the start until the segment with the last glob so subdirs are Globs from the start until the segment with the last glob so subdirs are
created if they didn't exist previously. created if they didn't exist previously.
""" """
expanded = expand(dest) expanded = _expand(self.dest)
if not _GLOB_MAGIC.search(str(expanded)): if not _GLOB_MAGIC.search(str(expanded)):
return [expanded] return [expanded]
@@ -50,12 +58,6 @@ def expand_dests(dest: str) -> list[Path]:
return [Path(match, *tail) for match in sorted(glob.glob(pattern))] return [Path(match, *tail) for match in sorted(glob.glob(pattern))]
@dataclass(frozen=True)
class ManifestEntry:
src: str
dest: str
@dataclass(frozen=True) @dataclass(frozen=True)
class ManifestComponent: class ManifestComponent:
name: str name: str