From 1c06996a0899d60c2df0d4eb2e5a653db00cb683 Mon Sep 17 00:00:00 2001 From: Tauwni <102470988+Tauwni@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:04:16 +0100 Subject: [PATCH] leonida_mods gui: on macOS, the missing-Tkinter hint names Homebrew's python-tk@ Homebrew's Python ships without Tkinter, so ./Mods.sh on a Mac stopped with the Debian hint (sudo apt install python3-tk). The hint now names the formula for the running version; docs/modding.md says it too. Co-Authored-By: Claude Opus 5.5 --- docs/modding.md | 2 +- tests/test_leonida_mods.py | 22 ++++++++++++++++++++++ tools/leonida_mods.py | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/modding.md b/docs/modding.md index 41ee5daed4..4073330147 100644 --- a/docs/modding.md +++ b/docs/modding.md @@ -38,7 +38,7 @@ paths that climb out of the package, links and manifests the runtime would rejec copies game data. On Windows, double-click **`Mods.bat`** for the Tkinter window (on Linux and macOS, run **`./Mods.sh`**; it needs -Tkinter, `python3-tk` on Debian and Ubuntu): choose the port folder, install a ZIP or folder, +Tkinter, `python3-tk` on Debian and Ubuntu, `brew install python-tk@3.N` for Homebrew's Python 3.N): choose the port folder, install a ZIP or folder, toggle a mod, create a swap, pack or remove one, and launch `gta6rt` normally or as a dry run. The GUI uses the same standard-library code as the CLI below. diff --git a/tests/test_leonida_mods.py b/tests/test_leonida_mods.py index 6204e9c9fb..fc4ba2cd06 100644 --- a/tests/test_leonida_mods.py +++ b/tests/test_leonida_mods.py @@ -242,6 +242,28 @@ def test_gui_is_an_explicit_lazy_tkinter_entry_point(self): args = leonida_mods.build_parser().parse_args(["--dir", "mods", "gui"]) self.assertEqual(args.command, "gui") + def test_missing_tkinter_names_the_platform_package(self): + # Homebrew's Python has no Tkinter: the hint names python-tk@, not the Debian package. + from unittest import mock + import builtins + real_import = builtins.__import__ + + def no_tkinter(name, *args, **kwargs): + if name == "tkinter" or name.startswith("tkinter."): + raise ImportError("No module named '_tkinter'") + return real_import(name, *args, **kwargs) + + args = leonida_mods.build_parser().parse_args(["--dir", "mods", "gui"]) + for platform, osname, want in (("darwin", "posix", "brew install python-tk@%d.%d" % sys.version_info[:2]), + ("linux", "posix", "sudo apt install python3-tk"), + ("win32", "nt", "python.org with Tcl/Tk")): + with self.subTest(platform=platform), mock.patch("builtins.__import__", no_tkinter), \ + mock.patch.object(leonida_mods.sys, "platform", platform), \ + mock.patch.object(leonida_mods.os, "name", osname): + with self.assertRaises(leonida_mods.ModsError) as ctx: + leonida_mods.run_gui(args, None) + self.assertIn(want, str(ctx.exception)) + def test_windows_launcher_opens_the_gui(self): launcher = (ROOT / "Mods.bat").read_text(encoding="utf-8") self.assertIn("leonida_mods.py", launcher) diff --git a/tools/leonida_mods.py b/tools/leonida_mods.py index b851182eb9..a8fcb3b0c5 100644 --- a/tools/leonida_mods.py +++ b/tools/leonida_mods.py @@ -639,6 +639,9 @@ def run_gui(args: argparse.Namespace, initial_mods_dir: str | None) -> int: from tkinter import filedialog, messagebox, ttk except ImportError as exc: hint = ("on Windows install Python from python.org with Tcl/Tk" if os.name == "nt" else + # Homebrew's Python ships without Tkinter: it is a separate formula per Python version. + f"brew install python-tk@{sys.version_info[0]}.{sys.version_info[1]} (or use the python.org installer)" + if sys.platform == "darwin" else "install your distribution's Tkinter package (Debian and Ubuntu: sudo apt install python3-tk)") raise ModsError(f"Tkinter is not installed; {hint}") from exc