File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/python3
22
3+ import shutil
34import sys
45import warnings
56from subprocess import DEVNULL , PIPE
@@ -34,12 +35,15 @@ def launch(cmd: str, **kwargs: Any) -> None:
3435
3536 Args:
3637 cmd: command string to execute as subprocess"""
37- if sys .platform == "win32" and not cmd .split (" " )[0 ].endswith (".cmd" ):
38- if " " in cmd :
39- cmd = cmd .replace (" " , ".cmd " , 1 )
40- else :
41- cmd += ".cmd"
4238 cmd_list = cmd .split (" " )
39+ if sys .platform == "win32" :
40+ executable = cmd_list [0 ]
41+ resolved = shutil .which (executable )
42+ if resolved is not None :
43+ cmd_list [0 ] = resolved
44+ elif not executable .endswith (".cmd" ):
45+ cmd_list [0 ] = f"{ executable } .cmd"
46+
4347 cmd_list .append ("--quiet" )
4448 for key , value in kwargs .items ():
4549 if value is None or value is False :
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def test_anvil_launcher_keeps_falsy_command_values(popen_calls):
3030 steps_tracing = True ,
3131 )
3232
33- cmd_list , _ = calls .pop ()
33+ cmd_list , _ = popen_calls .pop ()
3434
3535 assert cmd_list == [
3636 "anvil" ,
@@ -45,6 +45,32 @@ def test_anvil_launcher_keeps_falsy_command_values(popen_calls):
4545 assert "--block-time" not in cmd_list
4646
4747
48+ def test_anvil_launcher_uses_resolved_windows_executable (monkeypatch , popen_calls ):
49+ monkeypatch .setattr (anvil .sys , "platform" , "win32" )
50+ monkeypatch .setattr (
51+ anvil .shutil ,
52+ "which" ,
53+ lambda executable : r"C:\Users\runner\.foundry\bin\anvil.exe"
54+ if executable == "anvil"
55+ else None ,
56+ )
57+
58+ anvil .launch ("anvil" )
59+
60+ cmd_list , _ = popen_calls .pop ()
61+ assert cmd_list [0 ] == r"C:\Users\runner\.foundry\bin\anvil.exe"
62+
63+
64+ def test_anvil_launcher_falls_back_to_cmd_on_windows (monkeypatch , popen_calls ):
65+ monkeypatch .setattr (anvil .sys , "platform" , "win32" )
66+ monkeypatch .setattr (anvil .shutil , "which" , lambda _ : None )
67+
68+ anvil .launch ("anvil" )
69+
70+ cmd_list , _ = popen_calls .pop ()
71+ assert cmd_list [0 ] == "anvil.cmd"
72+
73+
4874def test_anvil_launcher_does_not_set_default_balance (popen_calls ):
4975 anvil .launch ("anvil" )
5076
You can’t perform that action at this time.
0 commit comments