Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post scripts are now added when the job is being set up #146

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/tcutility/job/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, test_mode: bool = False, overwrite: bool = False, wait_for_fi
self.wait_for_finish = wait_for_finish
self._preambles = []
self._postambles = []
self._postscripts = []

def __enter__(self):
return self
Expand Down Expand Up @@ -104,6 +105,10 @@ def run(self):
log.info(f'Skipping calculation {j(self.rundir, self.name)}, it is already finished or currently pending or running.')
return

# write the post-script calls to the post-ambles:
for postscript in self._postscripts:
print(postscript)
self._postambles.append(f'python {postscript[0]} {" ".join(postscript[1])}')
# setup the job and check if it was successfull
setup_success = self._setup_job()

Expand Down Expand Up @@ -155,9 +160,19 @@ def add_postamble(self, line: str):
'''
self._postambles.append(line)

def add_postscript(self, script):
self.add_postamble(f'cd {self.workdir}')
self.add_postamble(f'python {script.__file__}')
def add_postscript(self, script, *args):
'''
Add a post-script to this calculation.
This should be either a Python module with a __file__ attribute or the path to a Python script.
The post-script will be called with Python and any given args will be added as arguments when calling the script.

Args:
script: a Python object with a __file__ attribute or the file-path to a script.
*args: positional arguments to pass to the post-script.
'''
if not isinstance(script, str):
script = script.__file__
self._postscripts.append((script, args))

def dependency(self, otherjob: 'Job'):
'''
Expand Down
Loading