From b49e9c14c816e232e87ef96648811e61b8dc1b94 Mon Sep 17 00:00:00 2001 From: "J. George" Date: Tue, 9 Apr 2024 10:08:50 +0200 Subject: [PATCH] Enable export of environment variables plus lobster run as a command (#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 --- custodian/lobster/jobs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custodian/lobster/jobs.py b/custodian/lobster/jobs.py index f2a79ac9..6b02c9a1 100644 --- a/custodian/lobster/jobs.py +++ b/custodian/lobster/jobs.py @@ -2,6 +2,7 @@ import logging import os +import shlex import shutil import subprocess @@ -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)."""