From da9d37895e54bb7e7ff386ed5ff7d62760b8aadc Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Fri, 20 Mar 2026 06:51:05 +0800 Subject: [PATCH 1/3] Fix auto-upgrade to windowed mode with legacy installer. --- src/manage/scriptutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manage/scriptutils.py b/src/manage/scriptutils.py index 4dda417..784ab01 100644 --- a/src/manage/scriptutils.py +++ b/src/manage/scriptutils.py @@ -90,7 +90,7 @@ def _find_shebang_command(cmd, full_cmd, *, windowed=None): return cmd.get_install_to_run(f"PythonCore/{tag}", windowed=True) if sh_cmd.match("python*.exe"): tag = sh_cmd.name[6:-4] - return cmd.get_install_to_run(f"PythonCore/{tag}") + return cmd.get_install_to_run(f"PythonCore/{tag}", windowed=windowed) raise LookupError From 621dcb0b80c5113a752331e6a5b2a5269f2fe463 Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Fri, 20 Mar 2026 07:24:31 +0800 Subject: [PATCH 2/3] Update get_install_to_run() args in test --- tests/test_install_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_install_command.py b/tests/test_install_command.py index 9c76ae1..feda93d 100644 --- a/tests/test_install_command.py +++ b/tests/test_install_command.py @@ -288,7 +288,7 @@ def get_log_file(self): def get_installs(self): return self.installs - def get_install_to_run(self, tag): + def get_install_to_run(self, tag=None, script=None, *, windowed=False): for i in self.installs: if i["tag"] == tag or f"{i['company']}/{i['tag']}" == tag: return i From 6321223543eb5b188be777d1701779b3a19ced79 Mon Sep 17 00:00:00 2001 From: Jesse205 <2055675594@qq.com> Date: Fri, 20 Mar 2026 10:01:46 +0800 Subject: [PATCH 3/3] Added test_unmanaged_py_shebang --- tests/conftest.py | 8 +++++--- tests/test_scriptutils.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c4c59a3..9e79973 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -158,8 +158,10 @@ def __init__(self, global_dir, installs=[]): self.shebang_can_run_anything_silently = False self.scratch = {} - def get_installs(self, *, include_unmanaged=True, set_default=True): - return self.installs + def get_installs(self, *, include_unmanaged=False, set_default=True): + if include_unmanaged: + return self.installs + return [i for i in self.installs if not i.get("unmanaged", 0)] def get_install_to_run(self, tag, *, windowed=False): if windowed: @@ -171,7 +173,7 @@ def get_install_to_run(self, tag, *, windowed=False): company, _, tag = tag.replace("/", "\\").rpartition("\\") return [i for i in self.installs - if i["tag"] == tag and (not company or i["company"] == company)][0] + if (not tag or i["tag"] == tag) and (not company or i["company"] == company)][0] @pytest.fixture diff --git a/tests/test_scriptutils.py b/tests/test_scriptutils.py index 6165053..f81d575 100644 --- a/tests/test_scriptutils.py +++ b/tests/test_scriptutils.py @@ -157,6 +157,25 @@ def t(n): assert t("pythonw1.0")["executable"].match("pythonw.exe") +def test_unmanaged_py_shebang(fake_config, tmp_path): + inst = _fake_install("1.0", company="PythonCore", prefix=PurePath("C:\\TestRoot")) + inst["unmanaged"] = 1 + inst["run-for"] = [ + dict(name="python.exe", target=".\\python.exe"), + dict(name="pythonw.exe", target=".\\pythonw.exe", windowed=1), + ] + fake_config.installs[:] = [inst] + + def t(n): + return _find_shebang_command(fake_config, n, windowed=False) + + # Finds the install's default executable + assert t("python")["executable"].match("test-binary-1.0.exe") + assert t("python1.0")["executable"].match("test-binary-1.0.exe") + # Finds the install's run-for executable with windowed=1 + assert t("pythonw")["executable"].match("pythonw.exe") + assert t("pythonw1.0")["executable"].match("pythonw.exe") + @pytest.mark.parametrize("script, expect", [ ("# not a coding comment", None),