Skip to content

Commit

Permalink
Enable export of environment variables plus lobster run as a command (#…
Browse files Browse the repository at this point in the history
…326)

* Update jobs.py

* pre-commit auto-fixes

* refactor

* support both str and Sequence[str] in LobsterJob.run

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent f55c6fa commit b49e9c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custodian/lobster/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import shlex
import shutil
import subprocess

Expand Down Expand Up @@ -78,16 +79,17 @@ def setup(self, directory="./"):

def run(self, directory="./"):
"""Runs the job."""
cmd = self.lobster_cmd
# join split commands (e.g. from atomate and atomate2)
cmd = self.lobster_cmd if isinstance(self.lobster_cmd, str) else shlex.join(self.lobster_cmd)

logger.info(f"Running {' '.join(cmd)}")
logger.info(f"Running {cmd}")

with (
zopen(os.path.join(directory, self.output_file), "w") as f_std,
# use line buffering for stderr
zopen(os.path.join(directory, self.stderr_file), "w", buffering=1) as f_err,
):
# use line buffering for stderr
return subprocess.Popen(cmd, cwd=directory, stdout=f_std, stderr=f_err) # pylint: disable=R1732
return subprocess.run(cmd, stdout=f_std, stderr=f_err, shell=True, check=False)

def postprocess(self, directory="./"):
"""Will gzip relevant files (won't gzip custodian.json and other output files from the cluster)."""
Expand Down

0 comments on commit b49e9c1

Please sign in to comment.