diff --git a/docs/installer.md b/docs/installer.md index e01793a2..21a697b9 100644 --- a/docs/installer.md +++ b/docs/installer.md @@ -83,8 +83,9 @@ Ninja recompiles only those: a new or edited code cheat costs the lift (under a and a few dozen chunks, not a full compile, and the shaders stay prepared. `build-cache/rebuild.txt` holds the command that opens the setup window in its rebuild mode on the install folder -(`python -m installer.gui --rebuild `), one argument per line. When an enabled mod has code cheats or -ExeFS patch files the build lacks, `totk.exe` runs it at start and exits (`runtime/cheats.c` `rebuild_if_needed`); the +(`installer/gui.py --rebuild `, started through `python -c` so the release folder is on `sys.path` +whatever the working folder), one argument per line. When an enabled mod has code cheats or ExeFS patch files the build +lacks, `totk.exe` runs it at start and exits (`runtime/cheats.c` `rebuild_if_needed`); the window runs the setup on the folder at once and starts the game again when it succeeds. A failed or cancelled rebuild offers to start the game with the code it has; `build-cache/rebuild.skip` then keeps the same files from starting it again, until "Rebuild the game now" on the Cheats or Mods tab. `[mods] mods_rebuild = off` turns it off. The rebuild diff --git a/installer/gui.py b/installer/gui.py index f93e4635..40f0ff82 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -325,7 +325,10 @@ class App: self.fit() return self.form_error.configure(text='') - command = form.command(self.layout.python, root=self.layout.root if self.layout.dev else None, + # in a repository the Python running this window: the tools' embeddable Python there has no ._pth entry for + # the repository, so `-m installer` would not find the package + python = Path(sys.executable) if self.layout.dev else self.layout.python + command = form.command(python, root=self.layout.root if self.layout.dev else None, temp=self.run_args.get('temp'), verify_hashes=self.run_args.get('verify', False)) self.begin(command, self.layout.root) diff --git a/installer/steps.py b/installer/steps.py index 9db5d080..52a9f796 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -1031,14 +1031,22 @@ class Cleanup(Step): return {} +# Puts the release folder (the argument after -c) on sys.path and runs installer.gui with the rest. `-m installer.gui` +# finds the package only through the release Python's ._pth: the Linux release's Python and the dev-mode embeddable one +# lack that entry, and totk.exe starts the command in the install folder. +REBUILD_BOOT = ('import runpy, sys; sys.path.insert(0, sys.argv.pop(1)); ' + "runpy.run_module('installer.gui', run_name='__main__', alter_sys=True)") + + def rebuild_command(ctx): """The command that starts the setup window in its rebuild mode on this install folder (installer/gui.py - --rebuild): pythonw beside the setup's Python on Windows, so no console opens.""" + --rebuild): pythonw beside the setup's Python on Windows, so no console opens. In a repository that is the Python + running this setup: the tools' embeddable Python there has no tkinter.""" layout = ctx.layout - python = layout.python + python = Path(sys.executable) if layout.dev else layout.python if os.name == 'nt' and python.with_name('pythonw.exe').is_file(): python = python.with_name('pythonw.exe') - return [str(python), '-m', 'installer.gui', '--root', str(layout.root), '--rebuild', str(ctx.dest)] + return [str(python), '-c', REBUILD_BOOT, str(layout.root), '--root', str(layout.root), '--rebuild', str(ctx.dest)] def write_rebuild_command(ctx): diff --git a/tests/installer_test.py b/tests/installer_test.py index 3f773c32..66cc31c6 100644 --- a/tests/installer_test.py +++ b/tests/installer_test.py @@ -326,7 +326,7 @@ class CleanupTest(unittest.TestCase): self.expected = {'romfs': {'size': len(image), 'sha256': digest}} self.ctx = SimpleNamespace(reporter=Reporter(out=io.StringIO(), log_path=base / 'x.log'), dest=self.dest, temp=temp, lang='en-US', state={}, - layout=SimpleNamespace(ini_example=ROOT / 'totk.ini.example', + layout=SimpleNamespace(ini_example=ROOT / 'totk.ini.example', dev=False, python=base / 'python' / 'python.exe', root=base / 'release')) self.saved = steps.expected_update steps.expected_update = lambda ctx: self.expected @@ -353,8 +353,8 @@ class CleanupTest(unittest.TestCase): self.assertTrue((self.ctx.temp / 'gen').is_dir() and (self.ctx.temp / 'build').is_dir()) self.assertFalse((self.ctx.temp / 'check').exists()) lines = (self.dest / 'build-cache' / 'rebuild.txt').read_text(encoding='utf-8').splitlines() - self.assertEqual(lines[1:], ['-m', 'installer.gui', '--root', str(self.ctx.layout.root), '--rebuild', - str(self.dest)]) + self.assertEqual(lines[1:], ['-c', steps.REBUILD_BOOT, str(self.ctx.layout.root), '--root', + str(self.ctx.layout.root), '--rebuild', str(self.dest)]) def test_emptied_romfs_fails(self): for p in (self.dest / 'romfs').iterdir():