Skip to content

Commit

Permalink
Save experiment outputs + counters as environment variables (#445)
Browse files Browse the repository at this point in the history
Save run info as environment variables so they can accessed in userscripts
  • Loading branch information
jo-basevi authored Jun 14, 2024
1 parent 81dfd77 commit 8a4a1e2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions payu/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,22 @@ def resubmit(self):
cmd = shlex.split(cmd)
sp.call(cmd)

def set_userscript_env_vars(self):
"""Save information of output directories and current run to
environment variables, so they can be accessed via user-scripts"""
os.environ.update(
{
'PAYU_CURRENT_OUTPUT_DIR': self.output_path,
'PAYU_CURRENT_RESTART_DIR': self.restart_path,
'PAYU_ARCHIVE_DIR': self.archive_path,
'PAYU_CURRENT_RUN': str(self.counter)
}
)

def run_userscript(self, script_cmd):
# Setup environment variables with current run information
self.set_userscript_env_vars()

# First try to interpret the argument as a full command:
try:
sp.check_call(shlex.split(script_cmd))
Expand Down

0 comments on commit 8a4a1e2

Please sign in to comment.