From b9504c02607e2a3743943a6bd9593f71b1d7d3e3 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Mon, 15 Nov 2021 09:22:47 +0000 Subject: [PATCH] automatically find date, which, bash, env etc. using shutil.which() --- binarycpython/utils/condor.py | 2 +- binarycpython/utils/grid_options_defaults.py | 16 +++++++++------- binarycpython/utils/slurm.py | 9 ++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/binarycpython/utils/condor.py b/binarycpython/utils/condor.py index 96ae70e96..15fcb9db2 100644 --- a/binarycpython/utils/condor.py +++ b/binarycpython/utils/condor.py @@ -216,7 +216,7 @@ class condor(): # build the grid command grid_command = [ - os.path.join("/usr","bin","env"), + str(self.grid_options['condor_env']), sys.executable, pyscriptpath, ] + sys.argv[1:] + [ diff --git a/binarycpython/utils/grid_options_defaults.py b/binarycpython/utils/grid_options_defaults.py index 6e6e6535d..1b80b2e61 100644 --- a/binarycpython/utils/grid_options_defaults.py +++ b/binarycpython/utils/grid_options_defaults.py @@ -15,6 +15,7 @@ All the options starting with _ should not be changed by the user except when yo import datetime import os +import shutil import sys from binarycpython.utils.custom_logging_functions import temp_dir @@ -207,9 +208,10 @@ class grid_options_defaults(): "slurm_extra_settings": {}, # Dictionary of extra settings for Slurm to put in its launch script. "slurm_sbatch": "sbatch", # sbatch command "slurm_restart_dir" : None, # restart Slurm jobs from this directory - "slurm_bash" : "/bin/bash", # bash location for Slurm - "slurm_pwd" : "/usr/bin/pwd", # pwd command location for Slurm - "slurm_date" : "/usr/bin/date", # bash location for Slurm + "slurm_env" : shutil.which("env"), # env location for Slurm + "slurm_bash" : shutil.which("bash"), # bash location for Slurm + "slurm_pwd" : shutil.which("pwd"), # pwd command location for Slurm + "slurm_date" : shutil.which("date"), # bash location for Slurm ######################################## # Condor stuff @@ -239,10 +241,10 @@ class grid_options_defaults(): 'condor_save_joined_file':0, # if 1 then results/joined contains the results # (useful for debugging, otherwise a lot of work) 'condor_requirements':'', # job requirements - 'condor_usr_bin_env' : '/usr/bin/env', # /usr/bin/env location - 'condor_bash' : '/bin/bash', # bash executable location - "condor_pwd" : "/usr/bin/pwd", # pwd command location for Condor - "condor_date" : "/usr/bin/date", # bash location for Condor + 'condor_usr_bin_env' : shutil.which("env"), # /usr/bin/env location + 'condor_bash' : shutil.which("bash"), # bash executable location + "condor_pwd" : shutil.which("pwd"), # pwd command location for Condor + "condor_date" : shutil.which("date"), # bash location for Condor "condor_array_max_jobs" : None, # override for the max number of concurrent array jobs "condor_initial_dir" : None, # directory from which condor is run, if None is the directory in which your script is run "condor_submit" : "condor_submit", # the condor_submit command diff --git a/binarycpython/utils/slurm.py b/binarycpython/utils/slurm.py index 86f1abe55..8d4b77e52 100644 --- a/binarycpython/utils/slurm.py +++ b/binarycpython/utils/slurm.py @@ -175,19 +175,19 @@ class slurm(): # run a grid of stars only, leaving the results # in the appropriate outfile return False - + elif self.grid_options['slurm'] == 3: # joining : set the evolution type to "join" and return # False to continue self.grid_options['evolution_type'] = 'join' return False - + elif self.grid_options['slurm'] == 1: # if slurm=1, we should have no evolution type, we # set up the Slurm scripts and get them evolving # in a Slurm array self.grid_options['evolution_type'] = None - + # make dirs self.make_slurm_dirs() @@ -219,7 +219,7 @@ class slurm(): # build the grid command grid_command = [ - os.path.join("/usr","bin","env"), + str(grid_options['slurm_env']) sys.executable, str(lib_programname.get_path_executed_script()), ] + sys.argv[1:] + [ @@ -351,4 +351,3 @@ echo {slurm_dir}/results/$SLURM_ARRAY_JOB_ID.$SLURM_ARRAY_TASK_ID.gz >> {slurm_d # return True so we exit immediately return True - -- GitLab