@@ -30,25 +30,33 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
30
30
if match :
31
31
dockerRequirement ["dockerImageId" ] = re .sub (pattern = r'([a-z]*://)' , repl = r'' ,
32
32
string = dockerRequirement ["dockerPull" ])
33
- dockerRequirement ["dockerImageId" ] = re .sub (pattern = r'[:/]' , repl = r'-' ,
34
- string = dockerRequirement ["dockerImageId" ]) + ".img"
33
+ dockerRequirement ["dockerImageId" ] = re .sub (
34
+ pattern = r'[:/]' , repl = r'-' , string = dockerRequirement ["dockerImageId" ]) + ".img"
35
35
else :
36
- dockerRequirement ["dockerImageId" ] = re .sub (pattern = r'[:/]' , repl = r'-' ,
37
- string = dockerRequirement ["dockerPull" ]) + ".img"
36
+ dockerRequirement ["dockerImageId" ] = re .sub (
37
+ pattern = r'[:/]' , repl = r'-' , string = dockerRequirement ["dockerPull" ]) + ".img"
38
38
dockerRequirement ["dockerPull" ] = "docker://" + dockerRequirement ["dockerPull" ]
39
39
40
40
# check if Singularity image is available in $SINGULARITY_CACHEDIR
41
- if "SINGULARITY_CACHEDIR" in os .environ \
42
- and os .path .isfile (os .path .join (os .environ ["SINGULARITY_CACHEDIR" ], dockerRequirement ["dockerImageId" ])):
43
- _logger .info ("Using local copy of Singularity image found in $SINGULARITY_CACHEDIR" )
44
- dockerRequirement ["dockerImageId" ] = os .path .join (os .environ ["SINGULARITY_CACHEDIR" ], dockerRequirement ["dockerImageId" ])
41
+ if "SINGULARITY_CACHEDIR" in os .environ and os .path .isfile (
42
+ os .path .join (os .environ ["SINGULARITY_CACHEDIR" ],
43
+ dockerRequirement ["dockerImageId" ])):
44
+ _logger .info ("Using local copy of Singularity image found in "
45
+ "$SINGULARITY_CACHEDIR" )
46
+ dockerRequirement ["dockerImageId" ] = os .path .join (
47
+ os .environ ["SINGULARITY_CACHEDIR" ],
48
+ dockerRequirement ["dockerImageId" ])
45
49
found = True
46
50
47
51
# check if Singularity image is available in $SINGULARITY_PULLFOLDER
48
- elif "SINGULARITY_PULLFOLDER" in os .environ \
49
- and os .path .isfile (os .path .join (os .environ ["SINGULARITY_PULLFOLDER" ], dockerRequirement ["dockerImageId" ])):
50
- _logger .info ("Using local copy of Singularity image found in $SINGULARITY_PULLFOLDER" )
51
- dockerRequirement ["dockerImageId" ] = os .path .join (os .environ ["SINGULARITY_PULLFOLDER" ], dockerRequirement ["dockerImageId" ])
52
+ elif "SINGULARITY_PULLFOLDER" in os .environ and os .path .isfile (
53
+ os .path .join (os .environ ["SINGULARITY_PULLFOLDER" ],
54
+ dockerRequirement ["dockerImageId" ])):
55
+ _logger .info ("Using local copy of Singularity image found in "
56
+ "$SINGULARITY_PULLFOLDER" )
57
+ dockerRequirement ["dockerImageId" ] = os .path .join (
58
+ os .environ ["SINGULARITY_PULLFOLDER" ],
59
+ dockerRequirement ["dockerImageId" ])
52
60
found = True
53
61
54
62
# check if Singularity image is available in current working directory
@@ -80,10 +88,10 @@ def get_from_requirements(self, r, req, pull_image, dry_run=False, force_pull=Fa
80
88
errmsg = None
81
89
try :
82
90
subprocess .check_output (["singularity" , "--version" ])
83
- except subprocess .CalledProcessError as e :
84
- errmsg = "Cannot execute 'singularity --version' " + Text ( e )
85
- except OSError as e :
86
- errmsg = "'singularity' executable not found: " + Text ( e )
91
+ except subprocess .CalledProcessError as err :
92
+ errmsg = "Cannot execute 'singularity --version' {}" . format ( err )
93
+ except OSError as err :
94
+ errmsg = "'singularity' executable not found: {}" . format ( err )
87
95
88
96
if errmsg :
89
97
if req :
@@ -95,7 +103,8 @@ def get_from_requirements(self, r, req, pull_image, dry_run=False, force_pull=Fa
95
103
return os .path .abspath (r ["dockerImageId" ])
96
104
else :
97
105
if req :
98
- raise WorkflowException (u"Container image %s not found" % r ["dockerImageId" ])
106
+ raise WorkflowException (u"Container image {} not "
107
+ "found" .format (r ["dockerImageId" ]))
99
108
100
109
return None
101
110
@@ -104,7 +113,7 @@ def add_volumes(self, pathmapper, runtime, stage_output):
104
113
105
114
host_outdir = self .outdir
106
115
container_outdir = self .builder .outdir
107
- for src , vol in pathmapper .items ():
116
+ for _ , vol in pathmapper .items ():
108
117
if not vol .staged :
109
118
continue
110
119
if stage_output :
@@ -119,13 +128,15 @@ def add_volumes(self, pathmapper, runtime, stage_output):
119
128
if vol .type in ("File" , "Directory" ):
120
129
if not vol .resolved .startswith ("_:" ):
121
130
runtime .append (u"--bind" )
122
- runtime .append ("%s:%s:ro" % (
123
- docker_windows_path_adjust (vol .resolved ), docker_windows_path_adjust (containertgt )))
131
+ runtime .append ("{}:{}:ro" .format (
132
+ docker_windows_path_adjust (vol .resolved ),
133
+ docker_windows_path_adjust (containertgt )))
124
134
elif vol .type == "WritableFile" :
125
135
if self .inplace_update :
126
136
runtime .append (u"--bind" )
127
- runtime .append ("%s:%s:rw" % (
128
- docker_windows_path_adjust (vol .resolved ), docker_windows_path_adjust (containertgt )))
137
+ runtime .append ("{}:{}:rw" .format (
138
+ docker_windows_path_adjust (vol .resolved ),
139
+ docker_windows_path_adjust (containertgt )))
129
140
else :
130
141
shutil .copy (vol .resolved , host_outdir_tgt )
131
142
ensure_writable (host_outdir_tgt )
@@ -135,28 +146,32 @@ def add_volumes(self, pathmapper, runtime, stage_output):
135
146
else :
136
147
if self .inplace_update :
137
148
runtime .append (u"--bind" )
138
- runtime .append ("%s:%s:rw" % (
139
- docker_windows_path_adjust (vol .resolved ), docker_windows_path_adjust (containertgt )))
149
+ runtime .append ("{}:{}:rw" .format (
150
+ docker_windows_path_adjust (vol .resolved ),
151
+ docker_windows_path_adjust (containertgt )))
140
152
else :
141
153
shutil .copytree (vol .resolved , vol .target )
142
154
elif vol .type == "CreateFile" :
143
155
createtmp = os .path .join (host_outdir , os .path .basename (vol .target ))
144
- with open (createtmp , "wb" ) as f :
145
- f .write (vol .resolved .encode ("utf-8" ))
156
+ with open (createtmp , "wb" ) as tmp :
157
+ tmp .write (vol .resolved .encode ("utf-8" ))
146
158
runtime .append (u"--bind" )
147
- runtime .append (
148
- "%s:%s:ro" % (docker_windows_path_adjust (createtmp ), docker_windows_path_adjust (vol .target )))
159
+ runtime .append ("{}:{}:ro" .format (
160
+ docker_windows_path_adjust (createtmp ),
161
+ docker_windows_path_adjust (vol .target )))
149
162
150
163
def create_runtime (self , env , rm_container = True , record_container_id = False , cidfile_dir = "" ,
151
164
cidfile_prefix = "" , ** kwargs ):
152
165
# type: (MutableMapping[Text, Text], bool, bool, Text, Text, **Any) -> List
153
166
154
167
runtime = [u"singularity" , u"--quiet" , u"exec" , u"--contain" ]
155
168
runtime .append (u"--bind" )
156
- runtime .append (
157
- u"%s:%s:rw" % (docker_windows_path_adjust (os .path .realpath (self .outdir )), self .builder .outdir ))
169
+ runtime .append (u"{}:{}:rw" .format (
170
+ docker_windows_path_adjust (os .path .realpath (self .outdir )),
171
+ self .builder .outdir ))
158
172
runtime .append (u"--bind" )
159
- runtime .append (u"%s:%s:rw" % (docker_windows_path_adjust (os .path .realpath (self .tmpdir )), "/tmp" ))
173
+ runtime .append (u"{}:{}:rw" .format (
174
+ docker_windows_path_adjust (os .path .realpath (self .tmpdir )), "/tmp" ))
160
175
161
176
self .add_volumes (self .pathmapper , runtime , stage_output = False )
162
177
if self .generatemapper :
@@ -172,6 +187,6 @@ def create_runtime(self, env, rm_container=True, record_container_id=False, cidf
172
187
env ["SINGULARITYENV_TMPDIR" ] = "/tmp"
173
188
env ["SINGULARITYENV_HOME" ] = self .builder .outdir
174
189
175
- for t , v in self .environment .items ():
176
- env ["SINGULARITYENV_" + t ] = v
190
+ for name , value in self .environment .items ():
191
+ env ["SINGULARITYENV_{}" . format ( name ) ] = value
177
192
return runtime
0 commit comments