diff --git a/src/manage/scriptutils.py b/src/manage/scriptutils.py index 784ab01..d203d8c 100644 --- a/src/manage/scriptutils.py +++ b/src/manage/scriptutils.py @@ -48,8 +48,16 @@ def _find_shebang_command(cmd, full_cmd, *, windowed=None): if not sh_cmd.match("*.exe"): sh_cmd = sh_cmd.with_name(sh_cmd.name + ".exe") - is_wdefault = sh_cmd.match("pythonw.exe") or sh_cmd.match("pyw.exe") - is_default = is_wdefault or sh_cmd.match("python.exe") or sh_cmd.match("py.exe") + is_wdefault = ( + sh_cmd.match("pythonw.exe") + or sh_cmd.match("pyw.exe") + or sh_cmd.match("pythonw3.exe") + ) + is_default = is_wdefault or ( + sh_cmd.match("python.exe") + or sh_cmd.match("py.exe") + or sh_cmd.match("python3.exe") + ) # Internal logic error, but non-fatal, if it has no value assert windowed is not None diff --git a/tests/conftest.py b/tests/conftest.py index c4ec097..a08d35f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -178,8 +178,15 @@ def get_install_to_run(self, tag, *, windowed=False): return i company, _, tag = tag.replace("/", "\\").rpartition("\\") - return [i for i in self.installs - if (not tag or i["tag"] == tag) and (not company or i["company"] == company)][0] + try: + found = [i for i in self.installs + if (not tag or i["tag"] == tag) and (not company or i["company"] == company)] + except LookupError as ex: + # LookupError is expected from this function, so make sure we don't raise it here + raise RuntimeError from ex + if found: + return found[0] + raise LookupError(tag) def ask_yn(self, question): return False if self.confirm else True diff --git a/tests/test_scriptutils.py b/tests/test_scriptutils.py index f81d575..9ccf506 100644 --- a/tests/test_scriptutils.py +++ b/tests/test_scriptutils.py @@ -139,8 +139,8 @@ def test_read_shebang_windowed(fake_config, tmp_path, script, expect, windowed): def test_default_py_shebang(fake_config, tmp_path): inst = _fake_install("1.0", company="PythonCore", prefix=PurePath("C:\\TestRoot"), default=True) inst["run-for"] = [ - dict(name="python.exe", target=".\\python.exe"), - dict(name="pythonw.exe", target=".\\pythonw.exe", windowed=1), + dict(name="othername.exe", target=".\\test-binary-1.0.exe"), + dict(name="othernamew.exe", target=".\\test-binary-1.0-w.exe", windowed=1), ] fake_config.installs[:] = [inst] @@ -150,11 +150,13 @@ def t(n): # Finds the install's default executable assert t("python")["executable"].match("test-binary-1.0.exe") assert t("py")["executable"].match("test-binary-1.0.exe") + assert t("python3")["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("pyw")["executable"].match("pythonw.exe") - assert t("pythonw1.0")["executable"].match("pythonw.exe") + assert t("pythonw")["executable"].match("test-binary-1.0-w.exe") + assert t("pyw")["executable"].match("test-binary-1.0-w.exe") + assert t("pythonw3")["executable"].match("test-binary-1.0-w.exe") + assert t("pythonw1.0")["executable"].match("test-binary-1.0-w.exe") def test_unmanaged_py_shebang(fake_config, tmp_path):