Skip to content

Commit 2bdea91

Browse files
authored
Fix shebang auto-upgrade to windowed mode for fallback python.exe commands (#286)
1 parent 8041d6f commit 2bdea91

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

src/manage/scriptutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _find_shebang_command(cmd, full_cmd, *, windowed=None):
9090
return cmd.get_install_to_run(f"PythonCore/{tag}", windowed=True)
9191
if sh_cmd.match("python*.exe"):
9292
tag = sh_cmd.name[6:-4]
93-
return cmd.get_install_to_run(f"PythonCore/{tag}")
93+
return cmd.get_install_to_run(f"PythonCore/{tag}", windowed=windowed)
9494

9595
raise LookupError
9696

tests/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ def __init__(self, global_dir, installs=[]):
158158
self.shebang_can_run_anything_silently = False
159159
self.scratch = {}
160160

161-
def get_installs(self, *, include_unmanaged=True, set_default=True):
162-
return self.installs
161+
def get_installs(self, *, include_unmanaged=False, set_default=True):
162+
if include_unmanaged:
163+
return self.installs
164+
return [i for i in self.installs if not i.get("unmanaged", 0)]
163165

164166
def get_install_to_run(self, tag, *, windowed=False):
165167
if windowed:
@@ -171,7 +173,7 @@ def get_install_to_run(self, tag, *, windowed=False):
171173

172174
company, _, tag = tag.replace("/", "\\").rpartition("\\")
173175
return [i for i in self.installs
174-
if i["tag"] == tag and (not company or i["company"] == company)][0]
176+
if (not tag or i["tag"] == tag) and (not company or i["company"] == company)][0]
175177

176178

177179
@pytest.fixture

tests/test_install_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_log_file(self):
288288
def get_installs(self):
289289
return self.installs
290290

291-
def get_install_to_run(self, tag):
291+
def get_install_to_run(self, tag=None, script=None, *, windowed=False):
292292
for i in self.installs:
293293
if i["tag"] == tag or f"{i['company']}/{i['tag']}" == tag:
294294
return i

tests/test_scriptutils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ def t(n):
157157
assert t("pythonw1.0")["executable"].match("pythonw.exe")
158158

159159

160+
def test_unmanaged_py_shebang(fake_config, tmp_path):
161+
inst = _fake_install("1.0", company="PythonCore", prefix=PurePath("C:\\TestRoot"))
162+
inst["unmanaged"] = 1
163+
inst["run-for"] = [
164+
dict(name="python.exe", target=".\\python.exe"),
165+
dict(name="pythonw.exe", target=".\\pythonw.exe", windowed=1),
166+
]
167+
fake_config.installs[:] = [inst]
168+
169+
def t(n):
170+
return _find_shebang_command(fake_config, n, windowed=False)
171+
172+
# Finds the install's default executable
173+
assert t("python")["executable"].match("test-binary-1.0.exe")
174+
assert t("python1.0")["executable"].match("test-binary-1.0.exe")
175+
# Finds the install's run-for executable with windowed=1
176+
assert t("pythonw")["executable"].match("pythonw.exe")
177+
assert t("pythonw1.0")["executable"].match("pythonw.exe")
178+
160179

161180
@pytest.mark.parametrize("script, expect", [
162181
("# not a coding comment", None),

0 commit comments

Comments
 (0)