Skip to content

Commit d7d8a6a

Browse files
committed
style: add None checks to process
1 parent 5fcf6e7 commit d7d8a6a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cwltool/process.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ def stageFiles(pm, stageFunc=None, ignoreWritable=False, symLink=True, secret_st
260260
ensure_writable(p.target)
261261
elif p.type == "CreateFile":
262262
with open(p.target, "wb") as n:
263-
if secret_store:
263+
if secret_store is not None:
264264
n.write(secret_store.retrieve(p.resolved).encode("utf-8"))
265265
else:
266266
n.write(p.resolved.encode("utf-8"))
267267
os.chmod(p.target, stat.S_IRUSR)
268268
elif p.type == "CreateWritableFile":
269269
with open(p.target, "wb") as n:
270-
if secret_store:
270+
if secret_store is not None:
271271
n.write(secret_store.retrieve(p.resolved).encode("utf-8"))
272272
else:
273273
n.write(p.resolved.encode("utf-8"))
@@ -519,7 +519,7 @@ def __init__(self,
519519
self.doc_schema = loadingContext.avsc_names
520520

521521
self.formatgraph = None # type: Optional[Graph]
522-
if self.doc_loader:
522+
if self.doc_loader is not None:
523523
self.formatgraph = self.doc_loader.graph
524524

525525
checkRequirements(self.tool, supportedProcessRequirements)
@@ -530,7 +530,7 @@ def __init__(self,
530530

531531
sd, _ = self.get_requirement("SchemaDefRequirement")
532532

533-
if sd:
533+
if sd is not None:
534534
sdtypes = sd["types"]
535535
av = schema.make_valid_avro(sdtypes, {t["name"]: t for t in avroize_type(sdtypes)}, set())
536536
for i in av:
@@ -596,13 +596,15 @@ def __init__(self,
596596

597597
dockerReq, is_req = self.get_requirement("DockerRequirement")
598598

599-
if dockerReq and dockerReq.get("dockerOutputDirectory") and not is_req:
599+
if dockerReq is not None and "dockerOutputDirectory" in dockerReq\
600+
and is_req is not None and not is_req:
600601
_logger.warning(SourceLine(
601602
item=dockerReq, raise_type=Text).makeError(
602603
"When 'dockerOutputDirectory' is declared, DockerRequirement "
603604
"should go in the 'requirements' section, not 'hints'."""))
604605

605-
if dockerReq and dockerReq.get("dockerOutputDirectory") == "/var/spool/cwl":
606+
if dockerReq is not None and is_req is not None\
607+
and dockerReq.get("dockerOutputDirectory") == "/var/spool/cwl":
606608
if is_req:
607609
# In this specific case, it is legal to have /var/spool/cwl, so skip the check.
608610
pass
@@ -636,7 +638,7 @@ def _init_job(self, joborder, runtimeContext):
636638
stagedir = u""
637639

638640
loadListingReq, _ = self.get_requirement("http://commonwl.org/cwltool#LoadListingRequirement")
639-
if loadListingReq:
641+
if loadListingReq is not None:
640642
loadListing = loadListingReq.get("loadListing")
641643
else:
642644
loadListing = "deep_listing" # will default to "no_listing" in CWL v1.1
@@ -648,15 +650,15 @@ def _init_job(self, joborder, runtimeContext):
648650
defaultDocker = runtimeContext.default_container
649651

650652
if (dockerReq or defaultDocker) and runtimeContext.use_container:
651-
if dockerReq:
653+
if dockerReq is not None:
652654
# Check if docker output directory is absolute
653655
if dockerReq.get("dockerOutputDirectory") and \
654656
dockerReq.get("dockerOutputDirectory").startswith('/'):
655657
outdir = dockerReq.get("dockerOutputDirectory")
656658
else:
657659
outdir = dockerReq.get("dockerOutputDirectory") or \
658660
runtimeContext.docker_outdir or random_outdir()
659-
elif defaultDocker:
661+
elif defaultDocker is not None:
660662
outdir = runtimeContext.docker_outdir or random_outdir()
661663
tmpdir = runtimeContext.docker_tmpdir or "/tmp"
662664
stagedir = runtimeContext.docker_stagedir or "/var/lib/cwl"
@@ -778,11 +780,11 @@ def evalResources(self, builder, runtimeContext):
778780
elif mx is None:
779781
mx = mn
780782

781-
if mn:
783+
if mn is not None:
782784
request[a + "Min"] = cast(int, mn)
783785
request[a + "Max"] = cast(int, mx)
784786

785-
if runtimeContext.select_resources:
787+
if runtimeContext.select_resources is not None:
786788
return runtimeContext.select_resources(request, runtimeContext)
787789
return {
788790
"cores": request["coresMin"],

0 commit comments

Comments
 (0)