Skip to content

Commit 409c67f

Browse files
committed
Modify PATH on userscripts call to include path to python executable
1 parent 6de3bb5 commit 409c67f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

payu/fsops.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ def needs_subprocess_shell(command: str) -> bool:
301301
return False
302302

303303

304+
def env_with_python_path():
305+
"""Return a copy of current environment variables with PATH
306+
modified to include the python interpreter"""
307+
# Get the directory of the current Python interpreter
308+
python_dir = os.path.dirname(sys.executable)
309+
310+
# Add Python interpreter to PATH
311+
env = os.environ.copy()
312+
env["PATH"] = python_dir + os.pathsep + env["PATH"]
313+
return env
314+
315+
304316
def _run_script(script_cmd: str, control_path: Path) -> None:
305317
"""Helper recursive function to attempt running a script command.
306318
@@ -315,9 +327,11 @@ def _run_script(script_cmd: str, control_path: Path) -> None:
315327
# First try to interpret the argument as a full command
316328
try:
317329
if needs_subprocess_shell(script_cmd):
318-
subprocess.check_call(script_cmd, shell=True)
330+
subprocess.check_call(script_cmd, shell=True,
331+
env=env_with_python_path())
319332
else:
320-
subprocess.check_call(shlex.split(script_cmd))
333+
subprocess.check_call(shlex.split(script_cmd),
334+
env=env_with_python_path())
321335
print(script_cmd)
322336

323337
except FileNotFoundError:

0 commit comments

Comments
 (0)