Skip to content
Merged
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
12 changes: 10 additions & 2 deletions src/manage/scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tests/test_scriptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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):
Expand Down
Loading