Skip to content

Commit 6fe9cd7

Browse files
authored
Merge branch 'master' into workflowstep_valuefrom_dir_listing
2 parents b755800 + 440bbba commit 6fe9cd7

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

cwltool/command_line_tool.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import re
1010
import shutil
1111
import tempfile
12+
import threading
1213
from functools import cmp_to_key, partial
1314
from typing import (Any, Callable, Dict, # pylint: disable=unused-import
1415
Generator, List, Optional, Set, Text, Type, TYPE_CHECKING,
@@ -49,8 +50,8 @@
4950
ACCEPTLIST_EN_STRICT_RE = re.compile(r"^[a-zA-Z0-9._+-]+$")
5051
ACCEPTLIST_EN_RELAXED_RE = re.compile(r".*") # Accept anything
5152
ACCEPTLIST_RE = ACCEPTLIST_EN_STRICT_RE
52-
DEFAULT_CONTAINER_MSG =\
53-
"""We are on Microsoft Windows and not all components of this CWL description have a
53+
DEFAULT_CONTAINER_MSG = """
54+
We are on Microsoft Windows and not all components of this CWL description have a
5455
container specified. This means that these steps will be executed in the default container,
5556
which is %s.
5657
@@ -295,10 +296,10 @@ def job(self,
295296
separateDirs=False)
296297
_check_adjust = partial(check_adjust, cachebuilder)
297298
visit_class([cachebuilder.files, cachebuilder.bindings],
298-
("File", "Directory"), _check_adjust)
299+
("File", "Directory"), _check_adjust)
299300

300301
cmdline = flatten(list(map(cachebuilder.generate_arg, cachebuilder.bindings)))
301-
(docker_req, docker_is_req) = self.get_requirement("DockerRequirement")
302+
(docker_req, _) = self.get_requirement("DockerRequirement")
302303
if docker_req and runtimeContext.use_container:
303304
dockerimg = docker_req.get("dockerImageId") or docker_req.get("dockerPull")
304305
elif runtimeContext.default_container is not None and runtimeContext.use_container:
@@ -311,19 +312,23 @@ def job(self,
311312
# not really run using docker, just for hashing purposes
312313
keydict = {u"cmdline": cmdline}
313314

314-
if "stdout" in self.tool:
315-
keydict["stdout"] = self.tool["stdout"]
316-
for location, f in cachebuilder.pathmapper.items():
317-
if f.type == "File":
318-
checksum = next((e['checksum'] for e in cachebuilder.files
319-
if 'location' in e and e['location'] == location
320-
and 'checksum' in e
321-
and e['checksum'] != 'sha1$hash'), None)
322-
st = os.stat(f.resolved)
315+
for shortcut in ["stdout", "stderr"]: # later, add "stdin"
316+
if shortcut in self.tool:
317+
keydict[shortcut] = self.tool[shortcut]
318+
319+
for location, fobj in cachebuilder.pathmapper.items():
320+
if fobj.type == "File":
321+
checksum = next(
322+
(e['checksum'] for e in cachebuilder.files
323+
if 'location' in e and e['location'] == location
324+
and 'checksum' in e
325+
and e['checksum'] != 'sha1$hash'), None)
326+
fobj_stat = os.stat(fobj.resolved)
323327
if checksum:
324-
keydict[f.resolved] = [st.st_size, checksum]
328+
keydict[fobj.resolved] = [fobj_stat.st_size, checksum]
325329
else:
326-
keydict[f.resolved] = [st.st_size, int(st.st_mtime * 1000)]
330+
keydict[fobj.resolved] = [fobj_stat.st_size,
331+
int(fobj_stat.st_mtime * 1000)]
327332

328333
interesting = {"DockerRequirement",
329334
"EnvVarRequirement",
@@ -342,7 +347,8 @@ def job(self,
342347
keydictstr, cachekey)
343348

344349
jobcache = os.path.join(runtimeContext.cachedir, cachekey)
345-
jobcachepending = jobcache + ".pending"
350+
jobcachepending = "{}.{}.pending".format(
351+
jobcache, threading.current_thread().ident)
346352

347353
if os.path.isdir(jobcache) and not os.path.isfile(jobcachepending):
348354
if docker_req and runtimeContext.use_container:

cwltool/job.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import tempfile
1111
import uuid
1212
import datetime
13-
from threading import Lock, Timer
13+
from threading import Timer
1414
from abc import ABCMeta, abstractmethod
1515
from io import IOBase, open # pylint: disable=redefined-builtin
1616
from typing import (IO, Any, AnyStr, Callable, # pylint: disable=unused-import
@@ -196,10 +196,11 @@ def _setup(self, runtimeContext): # type: (RuntimeContext) -> None
196196
self.generatemapper = self.make_path_mapper(
197197
cast(List[Any], self.generatefiles["listing"]),
198198
self.builder.outdir, runtimeContext, False)
199-
_logger.debug(u"[job %s] initial work dir %s", self.name,
200-
json_dumps({p: self.generatemapper.mapper(p)
201-
for p in self.generatemapper.files()},
202-
indent=4))
199+
if _logger.isEnabledFor(logging.DEBUG):
200+
_logger.debug(
201+
u"[job %s] initial work dir %s", self.name,
202+
json_dumps({p: self.generatemapper.mapper(p)
203+
for p in self.generatemapper.files()}, indent=4))
203204

204205
def _execute(self,
205206
runtime, # type: List[Text]
@@ -250,12 +251,12 @@ def _execute(self,
250251
stdout_path = None
251252
if self.stdout:
252253
absout = os.path.join(self.outdir, self.stdout)
253-
dn = os.path.dirname(absout)
254-
if dn and not os.path.exists(dn):
255-
os.makedirs(dn)
254+
dnout = os.path.dirname(absout)
255+
if dnout and not os.path.exists(dnout):
256+
os.makedirs(dnout)
256257
stdout_path = absout
257258

258-
commands = [Text(x) for x in (runtime + self.command_line)]
259+
commands = [Text(x) for x in runtime + self.command_line]
259260
if runtimeContext.secret_store:
260261
commands = runtimeContext.secret_store.retrieve(commands)
261262
env = runtimeContext.secret_store.retrieve(env)
@@ -308,8 +309,8 @@ def _execute(self,
308309
else:
309310
_logger.exception("Exception while running job")
310311
processStatus = "permanentFail"
311-
except WorkflowException as e:
312-
_logger.error(u"[job %s] Job error:\n%s" % (self.name, e))
312+
except WorkflowException as err:
313+
_logger.error(u"[job %s] Job error:\n%s", self.name, err)
313314
processStatus = "permanentFail"
314315
except Exception as e:
315316
_logger.exception("Exception while running job")

cwltool/workflow.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def do_output_callback(self, final_output_callback):
254254
datetime.datetime.now())
255255
self.prov_obj.finalize_prov_profile(str(self.name))
256256
_logger.info(u"[%s] completed %s", self.name, self.processStatus)
257-
_logger.debug(u"[%s] %s", self.name, json_dumps(wo, indent=4))
257+
if _logger.isEnabledFor(logging.DEBUG):
258+
_logger.debug(u"[%s] %s", self.name, json_dumps(wo, indent=4))
258259

259260
self.did_callback = True
260261

@@ -417,8 +418,8 @@ def job(self,
417418
self.state = {}
418419
self.processStatus = "success"
419420

420-
_logger.debug(u"[%s] %s", self.name, json_dumps(joborder,
421-
indent=4))
421+
if _logger.isEnabledFor(logging.DEBUG):
422+
_logger.debug(u"[%s] %s", self.name, json_dumps(joborder, indent=4))
422423

423424
runtimeContext = runtimeContext.copy()
424425
runtimeContext.outdir = None

0 commit comments

Comments
 (0)