Skip to content

Commit

Permalink
Add bash functions to env.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Micket committed Sep 30, 2024
1 parent d3c0127 commit 04e3b66
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def create_cmd_scripts(cmd_str, work_dir, env, tmpdir, out_file, err_file):
if env is None:
env = os.environ.copy()

# Decode any declared bash functions
proc = subprocess.Popen('declare -f', stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
env=env, shell=True, executable='bash')
(bash_functions, _) = proc.communicate()

env_fp = os.path.join(tmpdir, 'env.sh')
with open(env_fp, 'w') as fid:
# unset all environment variables in current environment first to start from a clean slate;
Expand All @@ -219,6 +224,8 @@ def create_cmd_scripts(cmd_str, work_dir, env, tmpdir, out_file, err_file):
fid.write('\n'.join(f'export {key}={shlex.quote(value)}' for key, value in sorted(env.items())
if not key.endswith('%')) + '\n')

fid.write(bash_functions.decode(errors='ignore') + '\n')

fid.write('\n\nPS1="eb-shell> "')

# define $EB_CMD_OUT_FILE to contain path to file with command output
Expand Down

0 comments on commit 04e3b66

Please sign in to comment.