Skip to content

Commit

Permalink
use run_shell_cmd in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Dec 31, 2023
1 parent 51159bf commit fc27fe2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions easybuild/scripts/findPythonDeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def can_run(cmd, argument):
return False


def run_cmd(arguments, action_desc, capture_stderr=True, **kwargs):
def run_shell_cmd(arguments, action_desc, capture_stderr=True, **kwargs):
"""Run the command and return the return code and output"""
extra_args = kwargs or {}
if sys.version_info[0] >= 3:
Expand All @@ -66,7 +66,7 @@ def run_cmd(arguments, action_desc, capture_stderr=True, **kwargs):
def run_in_venv(cmd, venv_path, action_desc):
"""Run the given command in the virtualenv at the given path"""
cmd = 'source %s/bin/activate && %s' % (venv_path, cmd)
return run_cmd(cmd, action_desc, shell=True, executable='/bin/bash')
return run_shell_cmd(cmd, action_desc, shell=True, executable='/bin/bash')


def get_dep_tree(package_spec, verbose):
Expand All @@ -78,7 +78,7 @@ def get_dep_tree(package_spec, verbose):
venv_dir = os.path.join(tmp_dir, 'venv')
if verbose:
print('Creating virtualenv at ' + venv_dir)
run_cmd(['virtualenv', '--system-site-packages', venv_dir], action_desc='create virtualenv')
run_shell_cmd(['virtualenv', '--system-site-packages', venv_dir], action_desc='create virtualenv')
if verbose:
print('Updating pip in virtualenv')
run_in_venv('pip install --upgrade pip', venv_dir, action_desc='update pip')
Expand Down Expand Up @@ -169,7 +169,7 @@ def print_deps(package, verbose):
sys.exit(1)
if args.verbose:
print('Checking with EasyBuild for missing dependencies')
missing_dep_out = run_cmd(['eb', args.ec, '--missing'],
missing_dep_out = run_shell_cmd(['eb', args.ec, '--missing'],
capture_stderr=False,
action_desc='Get missing dependencies'
)
Expand All @@ -189,15 +189,15 @@ def print_deps(package, verbose):
os.chdir(tmp_dir)
if args.verbose:
print('Running EasyBuild to get build environment')
run_cmd(['eb', ec_arg, '--dump-env', '--force'], action_desc='Dump build environment')
run_shell_cmd(['eb', ec_arg, '--dump-env', '--force'], action_desc='Dump build environment')
os.chdir(old_dir)

cmd = "source %s/*.env && python %s '%s'" % (tmp_dir, sys.argv[0], args.package)
if args.verbose:
cmd += ' --verbose'
print('Restarting script in new build environment')

out = run_cmd(cmd, action_desc='Run in new environment', shell=True, executable='/bin/bash')
out = run_shell_cmd(cmd, action_desc='Run in new environment', shell=True, executable='/bin/bash')
print(out)
else:
if not can_run('virtualenv', '--version'):
Expand Down
10 changes: 5 additions & 5 deletions easybuild/scripts/mk_tmpl_easyblock_for.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
import easybuild.tools.toolchain as toolchain
%(parent_import)s
from easybuild.framework.easyconfig import CUSTOM, MANDATORY
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd
class %(class_name)s(%(parent)s):
Expand Down Expand Up @@ -150,7 +150,7 @@ def configure_step(self):
env.setvar('CUSTOM_ENV_VAR', 'foo')
cmd = "configure command"
run_cmd(cmd, log_all=True, simple=True, log_ok=True)
run_shell_cmd(cmd)
# complete configuration with configure_method of parent
super(%(class_name)s, self).configure_step()
Expand All @@ -167,20 +167,20 @@ def build_step(self):
# enable parallel build
par = self.cfg['parallel']
cmd = "build command --parallel %%d --compiler-family %%s" %% (par, comp_fam)
run_cmd(cmd, log_all=True, simple=True, log_ok=True)
run_shell_cmd(cmd)
def test_step(self):
\"\"\"Custom built-in test procedure for %(name)s.\"\"\"
if self.cfg['runtest']:
cmd = "test-command"
run_cmd(cmd, simple=True, log_all=True, log_ok=True)
run_shell_cmd(cmd)
def install_step(self):
\"\"\"Custom install procedure for %(name)s.\"\"\"
cmd = "install command"
run_cmd(cmd, log_all=True, simple=True, log_ok=True)
run_shell_cmd(cmd)
def sanity_check_step(self):
\"\"\"Custom sanity check for %(name)s.\"\"\"
Expand Down

0 comments on commit fc27fe2

Please sign in to comment.