Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/modding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
22 changes: 22 additions & 0 deletions tests/test_leonida_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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@<this version>, 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)
Expand Down
3 changes: 3 additions & 0 deletions tools/leonida_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading