Skip to content

Commit

Permalink
switch to run_shell_cmd where possible in easybuild.* modules
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Jan 3, 2024
1 parent 9cbd60f commit 7c30735
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
8 changes: 4 additions & 4 deletions easybuild/framework/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from easybuild.framework.easyconfig.templates import TEMPLATE_NAMES_EASYBLOCK_RUN_STEP, template_constant_dict
from easybuild.tools.build_log import EasyBuildError, raise_nosupport
from easybuild.tools.filetools import change_dir
from easybuild.tools.run import check_async_cmd, run_cmd
from easybuild.tools.run import check_async_cmd, run_cmd, run_shell_cmd


def resolve_exts_filter_template(exts_filter, ext):
Expand Down Expand Up @@ -274,14 +274,14 @@ def sanity_check_step(self):
elif exts_filter:
cmd, stdin = resolve_exts_filter_template(exts_filter, self)
# set log_ok to False so we can catch the error instead of run_cmd
(output, ec) = run_cmd(cmd, log_ok=False, simple=False, regexp=False, inp=stdin)
cmd_res = run_shell_cmd(cmd, fail_on_error=False, stdin=stdin)

if ec:
if cmd_res.exit_code:
if stdin:
fail_msg = 'command "%s" (stdin: "%s") failed' % (cmd, stdin)
else:
fail_msg = 'command "%s" failed' % cmd
fail_msg += "; output:\n%s" % output.strip()
fail_msg += "; output:\n%s" % cmd_res.output.strip()
self.log.warning("Sanity check for '%s' extension failed: %s", self.name, fail_msg)
res = (False, fail_msg)
# keep track of all reasons of failure
Expand Down
6 changes: 3 additions & 3 deletions easybuild/toolchains/linalg/flexiblas.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from easybuild.tools.toolchain.linalg import LinAlg

from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd
from easybuild.tools.systemtools import get_shared_lib_ext


Expand All @@ -48,11 +48,11 @@ def det_flexiblas_backend_libs():
# System-wide (config directory):
# OPENBLAS
# library = libflexiblas_openblas.so
out, _ = run_cmd("flexiblas list", simple=False, trace=False)
res = run_shell_cmd("flexiblas list", hidden=True)

shlib_ext = get_shared_lib_ext()
flexiblas_lib_regex = re.compile(r'library = (?P<lib>lib.*\.%s)' % shlib_ext, re.M)
flexiblas_libs = flexiblas_lib_regex.findall(out)
flexiblas_libs = flexiblas_lib_regex.findall(res.output)

backend_libs = []
for flexiblas_lib in flexiblas_libs:
Expand Down
18 changes: 9 additions & 9 deletions easybuild/tools/job/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from easybuild.tools.config import JOB_DEPS_TYPE_ABORT_ON_ERROR, JOB_DEPS_TYPE_ALWAYS_RUN, build_option
from easybuild.tools.job.backend import JobBackend
from easybuild.tools.filetools import which
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd


_log = fancylogger.getLogger('slurm', fname=False)
Expand Down Expand Up @@ -78,8 +78,8 @@ def __init__(self, *args, **kwargs):

def _check_version(self):
"""Check whether version of Slurm complies with required version."""
(out, _) = run_cmd("sbatch --version", trace=False)
slurm_ver = out.strip().split(' ')[-1]
res = run_shell_cmd("sbatch --version", hidden=True)
slurm_ver = res.output.strip().split(' ')[-1]
self.log.info("Found Slurm version %s", slurm_ver)

if LooseVersion(slurm_ver) < LooseVersion(self.REQ_VERSION):
Expand Down Expand Up @@ -116,16 +116,16 @@ def queue(self, job, dependencies=frozenset()):
else:
submit_cmd += ' --%s "%s"' % (key, job.job_specs[key])

(out, _) = run_cmd(submit_cmd, trace=False)
cmd_res = run_shell_cmd(submit_cmd, hidden=True)

jobid_regex = re.compile("^Submitted batch job (?P<jobid>[0-9]+)")

res = jobid_regex.search(out)
if res:
job.jobid = res.group('jobid')
regex_res = jobid_regex.search(cmd_res.output)
if regex_res:
job.jobid = regex_res.group('jobid')
self.log.info("Job submitted, got job ID %s", job.jobid)
else:
raise EasyBuildError("Failed to determine job ID from output of submission command: %s", out)
raise EasyBuildError("Failed to determine job ID from output of submission command: %s", cmd_res.output)

self._submitted.append(job)

Expand All @@ -142,7 +142,7 @@ def complete(self):
job_ids.append(job.jobid)

if job_ids:
run_cmd("scontrol release %s" % ' '.join(job_ids), trace=False)
run_shell_cmd("scontrol release %s" % ' '.join(job_ids), hidden=True)

submitted_jobs = '; '.join(["%s (%s): %s" % (job.name, job.module, job.jobid) for job in self._submitted])
print_msg("List of submitted jobs (%d): %s" % (len(self._submitted), submitted_jobs), log=self.log)
Expand Down
7 changes: 4 additions & 3 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
from easybuild.tools.module_naming_scheme.utilities import avail_module_naming_schemes
from easybuild.tools.modules import Lmod
from easybuild.tools.robot import det_robot_path
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd
from easybuild.tools.package.utilities import avail_package_naming_schemes
from easybuild.tools.toolchain.compiler import DEFAULT_OPT_LEVEL, OPTARCH_MAP_CHAR, OPTARCH_SEP, Compiler
from easybuild.tools.toolchain.toolchain import SYSTEM_TOOLCHAIN_NAME
Expand Down Expand Up @@ -1893,8 +1893,9 @@ def set_tmpdir(tmpdir=None, raise_error=False):
fd, tmptest_file = tempfile.mkstemp()
os.close(fd)
os.chmod(tmptest_file, 0o700)
if not run_cmd(tmptest_file, simple=True, log_ok=False, regexp=False, force_in_dry_run=True, trace=False,
stream_output=False, with_hooks=False):
res = run_shell_cmd(tmptest_file, fail_on_error=False, in_dry_run=True, hidden=True, stream_output=False,
with_hooks=False)
if res.exit_code:
msg = "The temporary directory (%s) does not allow to execute files. " % tempfile.gettempdir()
msg += "This can cause problems in the build process, consider using --tmpdir."
if raise_error:
Expand Down
4 changes: 2 additions & 2 deletions easybuild/tools/package/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import change_dir, which
from easybuild.tools.package.package_naming_scheme.pns import PackageNamingScheme
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd
from easybuild.tools.utilities import get_subclasses, import_available_modules


Expand Down Expand Up @@ -145,7 +145,7 @@ def package_with_fpm(easyblock):
])
cmd = ' '.join(cmdlist)
_log.debug("The flattened cmdlist looks like: %s", cmd)
run_cmd(cmdlist, log_all=True, simple=True, shell=False)
run_shell_cmd(cmdlist, use_bash=False)

_log.info("Created %s package(s) in %s", pkgtype, workdir)

Expand Down

0 comments on commit 7c30735

Please sign in to comment.