From a0af055f33b090f16c70f6f4783fa8b43e314c34 Mon Sep 17 00:00:00 2001 From: Justin Bollinger Date: Sat, 25 Apr 2026 19:14:53 -0400 Subject: [PATCH] feat(update): install system deps (transmission-daemon/p7zip) on upgrade Add _install_system_deps() called by _run_upgrade() after a successful git pull. Installs transmission-daemon (Linux) or transmission-cli brew formula (macOS) so users who upgrade don't need to re-run make install manually. Also corrects _run_upgrade to exit 1 on failure. Co-Authored-By: Claude Sonnet 4.6 --- hate_crack/main.py | 27 ++++++++++++++++++++++++--- tests/test_version_check.py | 8 +++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/hate_crack/main.py b/hate_crack/main.py index 1053d21..e197a87 100755 --- a/hate_crack/main.py +++ b/hate_crack/main.py @@ -946,6 +946,25 @@ def ascii_art(): ) +def _install_system_deps(): + """Best-effort install of system dependencies after an upgrade.""" + import subprocess + import sys + + plat = sys.platform + if plat == "darwin": + if subprocess.run(["which", "brew"], capture_output=True).returncode == 0: + print(" Installing/updating system dependencies via Homebrew...") + subprocess.run(["brew", "install", "transmission-cli", "p7zip"]) + else: + print(" [!] Homebrew not found — install transmission-cli and p7zip manually.") + elif plat.startswith("linux"): + print(" Installing/updating system dependencies via apt-get...") + subprocess.run(["sudo", "apt-get", "install", "-y", "transmission-daemon", "p7zip-full"]) + else: + print(f" [!] Unknown platform '{plat}' — install transmission-daemon and p7zip manually.") + + def _run_upgrade(): """Run `git pull && make clean && make && make install` in the repo root.""" import subprocess @@ -986,10 +1005,12 @@ def _run_upgrade(): shell=True, cwd=repo_root, ) - if result.returncode == 0: - print("\n Upgrade complete. Please restart hate_crack.\n") - else: + if result.returncode != 0: print("\n Upgrade failed. Check the output above for errors.\n") + raise SystemExit(1) + + _install_system_deps() + print("\n Upgrade complete. Please restart hate_crack.\n") raise SystemExit(0) diff --git a/tests/test_version_check.py b/tests/test_version_check.py index 4007c34..db21392 100644 --- a/tests/test_version_check.py +++ b/tests/test_version_check.py @@ -153,7 +153,7 @@ class TestCheckForUpdates: "subprocess.run", side_effect=[git_root_proc, make_proc] ) as mock_run, patch("shutil.which", return_value="/usr/local/bin/uv"), patch( "os.path.isfile", return_value=True - ), pytest.raises( + ), patch.object(hc_module, "_install_system_deps"), pytest.raises( SystemExit ): mock_requests.get.return_value = mock_resp @@ -236,7 +236,9 @@ class TestRunUpgrade: make_proc = MagicMock() make_proc.returncode = 0 - with patch("subprocess.run", side_effect=[git_root_proc, make_proc]) as mock_run, pytest.raises(SystemExit) as exc: + with patch("subprocess.run", side_effect=[git_root_proc, make_proc]) as mock_run, \ + patch.object(hc_module, "_install_system_deps"), \ + pytest.raises(SystemExit) as exc: hc_module._run_upgrade() assert exc.value.code == 0 @@ -259,7 +261,7 @@ class TestRunUpgrade: with patch("subprocess.run", side_effect=[git_root_proc, make_proc]), pytest.raises(SystemExit) as exc: hc_module._run_upgrade() - assert exc.value.code == 0 + assert exc.value.code == 1 output = capsys.readouterr().out assert "Upgrade failed" in output