Homebrew formula manager for macOS (brew).
Source code in src/personal_os_setup/tasks/managers/darwin_brew.py
| class DarwinBrewManager:
"""Homebrew formula manager for macOS (`brew`)."""
name = "brew"
def is_installed(self, package: str) -> bool:
brew = _ensure_brew()
if brew is None:
# If brew itself is missing, we cannot reliably report per-package
# status; treat as not installed.
return False
# `brew list --formula <name>` exits 0 if installed, non-zero otherwise.
res = run([brew, "list", "--formula", package], check=False)
return res.returncode == 0
def install(self, package: str) -> InstallResult:
brew = _ensure_brew()
if brew is None:
return missing_executable_install_result("brew", _BREW_HINT)
logger.info(f"Installing {package} via {self.name}...")
res = run([brew, "install", package], check=False)
if res.returncode == 0:
return InstallResult(ok=True, summary=f"Installed {package}")
return InstallResult(
ok=False, summary=f"Failed to install {package}", details=command_details(res)
)
def update(self) -> TaskResult:
return _run_brew_subcommand(["update"], action="brew update")
def upgrade(self) -> TaskResult:
return _run_brew_subcommand(["upgrade"], action="brew upgrade")
def cleanup(self) -> TaskResult:
return _run_brew_subcommand(["cleanup"], action="brew cleanup")
|