Skip to content

Commit 04e3b66

Browse files
committed
Add bash functions to env.sh
1 parent d3c0127 commit 04e3b66

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

easybuild/tools/run.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def create_cmd_scripts(cmd_str, work_dir, env, tmpdir, out_file, err_file):
208208
if env is None:
209209
env = os.environ.copy()
210210

211+
# Decode any declared bash functions
212+
proc = subprocess.Popen('declare -f', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
213+
env=env, shell=True, executable='bash')
214+
(bash_functions, _) = proc.communicate()
215+
211216
env_fp = os.path.join(tmpdir, 'env.sh')
212217
with open(env_fp, 'w') as fid:
213218
# unset all environment variables in current environment first to start from a clean slate;
@@ -219,6 +224,8 @@ def create_cmd_scripts(cmd_str, work_dir, env, tmpdir, out_file, err_file):
219224
fid.write('\n'.join(f'export {key}={shlex.quote(value)}' for key, value in sorted(env.items())
220225
if not key.endswith('%')) + '\n')
221226

227+
fid.write(bash_functions.decode(errors='ignore') + '\n')
228+
222229
fid.write('\n\nPS1="eb-shell> "')
223230

224231
# define $EB_CMD_OUT_FILE to contain path to file with command output

0 commit comments

Comments
 (0)