Skip to content

Commit eec6781

Browse files
committed
Updating building/caching scripts for how dependencies are checked
1 parent 15b9769 commit eec6781

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

resources/builder

+18-12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ function check(){
122122
}
123123

124124

125+
function require(){
126+
# Requires an executable is in $PATH, as a last resort it will attempt to load
127+
# the executable or dependency as a module
128+
# @INPUT $@ = List of dependencies or executables to check
129+
130+
for exe in "${@}"; do
131+
# Check if executable is in $PATH
132+
command -V ${exe} &> /dev/null && continue;
133+
# Try to load exe as lua module
134+
module load ${exe} &> /dev/null || \
135+
fatal "Failed to find or load '${exe}', not installed on target system."
136+
done
137+
}
138+
139+
125140
function submit(){
126141
# Submit jobs to the defined job scheduler or executor (i.e. slurm)
127142
# INPUT $1 = Snakemake Mode of execution
@@ -131,19 +146,9 @@ function submit(){
131146
# INPUT $5 = Singularity cache directory
132147
# INPUT $6 = Temporary directory for output files
133148

134-
# SLURM inherits the environment from which the job was launched
135-
# Try to purge modules all modules from environment
136-
command -V module &> /dev/null && module purge
137-
138-
# Check if singularity in $PATH
149+
# Check if singularity and snakemake are in $PATH
139150
# If not, try to module load singularity as a last resort
140-
command -V singularity &> /dev/null || module load singularity || \
141-
fatal "Fail to find or load 'singularity', not installed on target system."
142-
143-
# Check if snakemake in $PATH
144-
# If not, try to module load snakemake as a last resort
145-
command -V snakemake &> /dev/null || module load snakemake || \
146-
fatal "Fail to find or load 'snakemake', not installed on target system."
151+
require singularity snakemake
147152

148153
# Snakemake executor
149154
executor=${1}
@@ -248,3 +253,4 @@ function main(){
248253

249254
# Main: check usage, parse args, and run pipeline
250255
main "$@"
256+

resources/cacher

+16-5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ function check(){
102102
}
103103

104104

105+
function require(){
106+
# Requires an executable is in $PATH, as a last resort it will attempt to load
107+
# the executable or dependency as a module
108+
# @INPUT $@ = List of dependencies or executables to check
109+
110+
for exe in "${@}"; do
111+
# Check if executable is in $PATH
112+
command -V ${exe} &> /dev/null && continue;
113+
# Try to load exe as lua module
114+
module load ${exe} &> /dev/null || \
115+
fatal "Failed to find or load '${exe}', not installed on target system."
116+
done
117+
}
118+
119+
105120
function retry() {
106121
# Tries to run a cmd 5 times before failing
107122
# If a command is successful, it will break out of attempt loop
@@ -138,11 +153,7 @@ function _pull(){
138153
# INPUT $4 = Images to pull from DockerHub
139154

140155
# Check if singularity in $PATH
141-
# If not, try to module load singularity as a last resort
142-
command -V singularity &> /dev/null || {
143-
command -V module &> /dev/null &&
144-
module purge && module load singularity
145-
} || fatal "Fail to find or load 'singularity', not installed on target system."
156+
require singularity
146157

147158
# cache executor
148159
executor=${1}

0 commit comments

Comments
 (0)