Skip to content

Commit 02c86ea

Browse files
committed
🚸 Deduce shell in add_process if not specified
1 parent 2d0ec62 commit 02c86ea

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

‎simvue/executor.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ class CompletionCallback(typing.Protocol):
3535
def __call__(self, *, status_code: int, std_out: str, std_err: str) -> None: ...
3636

3737

38+
def get_current_shell() -> str | None:
39+
"""Return the users current shell executable."""
40+
try:
41+
_process = psutil.Process(os.getppid())
42+
return _process.exe()
43+
except psutil.Error:
44+
return None
45+
46+
3847
def _execute_process(
3948
proc_id: str,
4049
command: list[str],
@@ -231,9 +240,12 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
231240

232241
if executable:
233242
command += [f"{executable}"]
234-
else:
243+
elif pos_args:
235244
command += [pos_args[0]]
236245
pos_args.pop(0)
246+
elif executable := get_current_shell():
247+
command += [f"{executable}"]
248+
237249
if script:
238250
command += [f"{script}"]
239251

‎simvue/run.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from .config.user import SimvueConfiguration
3939

4040
from .factory.dispatch import Dispatcher
41-
from .executor import Executor
41+
from .executor import Executor, get_current_shell
4242
from .metrics import SystemResourceMeasurement
4343
from .models import FOLDER_REGEX, NAME_REGEX, MetricKeyString
4444
from .system import get_system
@@ -877,10 +877,12 @@ def callback_function(status_code: int, std_out: str, std_err: str) -> None:
877877
if executable:
878878
executable_str = f"{executable}"
879879
cmd_list += [executable_str]
880-
else:
880+
elif pos_args:
881881
cmd_list += [pos_args[0]]
882882
executable = pos_args[0]
883883
pos_args.pop(0)
884+
else:
885+
executable = get_current_shell()
884886

885887
for kwarg, val in cmd_kwargs.items():
886888
_quoted_val: str = f'"{val}"'

‎tests/functional/test_executor.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ def completion_callback(*_, success: dict[str, bool]=success, **__):
165165
folder=f"/simvue_unit_testing/{folder_id}",
166166
tags=[platform.system(), "simvue_client_tests", request.node.name]
167167
)
168+
print(os.environ.get("SHELL"))
168169
run.add_process(
169170
f"test_completion_callbacks_var_change_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
170-
"exit 0",
171+
c="exit 0",
172+
executable="bash" if any(shell in os.environ.get("SHELL", "") for shell in ("zsh", "bash")) else None,
171173
completion_callback=completion_callback
172174
)
173175

0 commit comments

Comments
 (0)