Skip to content

Commit 64dc158

Browse files
committed
style: add None checks to command_line_tool
1 parent 0c3e0b5 commit 64dc158

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

cwltool/command_line_tool.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ def make_job_runner(self,
234234
): # type: (...) -> Type[JobBase]
235235
dockerReq, _ = self.get_requirement("DockerRequirement")
236236
if not dockerReq and runtimeContext.use_container:
237-
if runtimeContext.find_default_container:
237+
if runtimeContext.find_default_container is not None:
238238
default_container = runtimeContext.find_default_container(self)
239-
if default_container:
239+
if default_container is not None:
240240
self.requirements.insert(0, {
241241
"class": "DockerRequirement",
242242
"dockerPull": default_container
@@ -248,7 +248,7 @@ def make_job_runner(self,
248248
DEFAULT_CONTAINER_MSG, windows_default_container_id,
249249
windows_default_container_id)
250250

251-
if dockerReq and runtimeContext.use_container:
251+
if dockerReq is not None and runtimeContext.use_container:
252252
if runtimeContext.singularity:
253253
return SingularityCommandLineJob
254254
return DockerCommandLineJob
@@ -285,7 +285,7 @@ def job(self,
285285
if self.metadata["cwlVersion"] == "v1.0":
286286
require_prefix = "http://commonwl.org/cwltool#"
287287

288-
workReuse = self.get_requirement(require_prefix+"WorkReuse")[0]
288+
workReuse, _ = self.get_requirement(require_prefix + "WorkReuse")
289289
enableReuse = workReuse.get("enableReuse", True) if workReuse else True
290290

291291
jobname = uniquename(runtimeContext.name or shortname(self.tool.get("id", "job")))
@@ -304,15 +304,15 @@ def job(self,
304304
("File", "Directory"), _check_adjust)
305305

306306
cmdline = flatten(list(map(cachebuilder.generate_arg, cachebuilder.bindings)))
307-
(docker_req, _) = self.get_requirement("DockerRequirement")
308-
if docker_req and runtimeContext.use_container:
307+
docker_req, _ = self.get_requirement("DockerRequirement")
308+
if docker_req is not None and runtimeContext.use_container:
309309
dockerimg = docker_req.get("dockerImageId") or docker_req.get("dockerPull")
310310
elif runtimeContext.default_container is not None and runtimeContext.use_container:
311311
dockerimg = runtimeContext.default_container
312312
else:
313313
dockerimg = None
314314

315-
if dockerimg:
315+
if dockerimg is not None:
316316
cmdline = ["docker", "run", dockerimg] + cmdline
317317
# not really run using docker, just for hashing purposes
318318
keydict = {u"cmdline": cmdline}
@@ -329,7 +329,7 @@ def job(self,
329329
and 'checksum' in e
330330
and e['checksum'] != 'sha1$hash'), None)
331331
fobj_stat = os.stat(fobj.resolved)
332-
if checksum:
332+
if checksum is not None:
333333
keydict[fobj.resolved] = [fobj_stat.st_size, checksum]
334334
else:
335335
keydict[fobj.resolved] = [fobj_stat.st_size,
@@ -413,8 +413,8 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
413413

414414
visit_class([builder.files, builder.bindings], ("File", "Directory"), _check_adjust)
415415

416-
initialWorkdir = self.get_requirement("InitialWorkDirRequirement")[0]
417-
if initialWorkdir:
416+
initialWorkdir, _ = self.get_requirement("InitialWorkDirRequirement")
417+
if initialWorkdir is not None:
418418
ls = [] # type: List[Dict[Text, Any]]
419419
if isinstance(initialWorkdir["listing"], string_types):
420420
ls = builder.do_eval(initialWorkdir["listing"])
@@ -482,8 +482,8 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
482482
if debug:
483483
_logger.debug(u"[job %s] command line bindings is %s", j.name,
484484
json_dumps(builder.bindings, indent=4))
485-
dockerReq = self.get_requirement("DockerRequirement")[0]
486-
if dockerReq and runtimeContext.use_container:
485+
dockerReq, _ = self.get_requirement("DockerRequirement")
486+
if dockerReq is not None and runtimeContext.use_container:
487487
out_prefix = getdefault(runtimeContext.tmp_outdir_prefix, 'tmp')
488488
j.outdir = runtimeContext.outdir or \
489489
tempfile.mkdtemp(prefix=out_prefix) # type: ignore
@@ -496,16 +496,16 @@ def rm_pending_output_callback(output_callbacks, jobcachepending,
496496
j.tmpdir = builder.tmpdir
497497
j.stagedir = builder.stagedir
498498

499-
inplaceUpdateReq = self.get_requirement("http://commonwl.org/cwltool#InplaceUpdateRequirement")[0]
499+
inplaceUpdateReq, _ = self.get_requirement("http://commonwl.org/cwltool#InplaceUpdateRequirement")
500500

501-
if inplaceUpdateReq:
501+
if inplaceUpdateReq is not None:
502502
j.inplace_update = inplaceUpdateReq["inplaceUpdate"]
503503
normalizeFilesDirs(j.generatefiles)
504504

505505
readers = {} # type: Dict[Text, Any]
506506
muts = set() # type: Set[Text]
507507

508-
if builder.mutation_manager:
508+
if builder.mutation_manager is not None:
509509
def register_mut(f):
510510
muts.add(f["location"])
511511
builder.mutation_manager.register_mutation(j.name, f)
@@ -529,30 +529,30 @@ def register_reader(f):
529529
adjustDirObjs(builder.files, register_reader)
530530
adjustDirObjs(builder.bindings, register_reader)
531531

532-
timelimit = self.get_requirement(require_prefix+"TimeLimit")[0]
533-
if timelimit:
532+
timelimit, _ = self.get_requirement(require_prefix + "TimeLimit")
533+
if timelimit is not None:
534534
with SourceLine(timelimit, "timelimit", validate.ValidationException, debug):
535535
j.timelimit = builder.do_eval(timelimit["timelimit"])
536536
if not isinstance(j.timelimit, int) or j.timelimit < 0:
537537
raise Exception("timelimit must be an integer >= 0, got: %s" % j.timelimit)
538538

539539
if self.metadata["cwlVersion"] == "v1.0":
540540
j.networkaccess = True
541-
networkaccess = self.get_requirement(require_prefix+"NetworkAccess")[0]
542-
if networkaccess:
541+
networkaccess, _ = self.get_requirement(require_prefix + "NetworkAccess")
542+
if networkaccess is not None:
543543
with SourceLine(networkaccess, "networkAccess", validate.ValidationException, debug):
544544
j.networkaccess = builder.do_eval(networkaccess["networkAccess"])
545545
if not isinstance(j.networkaccess, bool):
546546
raise Exception("networkAccess must be a boolean, got: %s" % j.networkaccess)
547547

548548
j.environment = {}
549-
evr = self.get_requirement("EnvVarRequirement")[0]
550-
if evr:
549+
evr, _ = self.get_requirement("EnvVarRequirement")
550+
if evr is not None:
551551
for t in evr["envDef"]:
552552
j.environment[t["envName"]] = builder.do_eval(t["envValue"])
553553

554-
shellcmd = self.get_requirement("ShellCommandRequirement")[0]
555-
if shellcmd:
554+
shellcmd, _ = self.get_requirement("ShellCommandRequirement")
555+
if shellcmd is not None:
556556
cmd = [] # type: List[Text]
557557
for b in builder.bindings:
558558
arg = builder.generate_arg(b)

0 commit comments

Comments
 (0)