Skip to content

Commit db0fe1c

Browse files
authored
Merge pull request #868 from pvanheus/random_output_dir
Add random outdir support
2 parents b738440 + a61ae1f commit db0fe1c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

cwltool/command_line_tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .stdfsaccess import StdFsAccess # pylint: disable=unused-import
4848
from .utils import (aslist, convert_pathsep_to_unix,
4949
docker_windows_path_adjust, json_dumps, onWindows,
50-
windows_default_container_id)
50+
random_outdir, windows_default_container_id)
5151
if TYPE_CHECKING:
5252
from .provenance import CreateProvProfile # pylint: disable=unused-import
5353

@@ -357,7 +357,7 @@ def job(self,
357357

358358
if os.path.isdir(jobcache) and not os.path.isfile(jobcachepending):
359359
if docker_req and runtimeContext.use_container:
360-
cachebuilder.outdir = runtimeContext.docker_outdir or "/var/spool/cwl"
360+
cachebuilder.outdir = runtimeContext.docker_outdir or random_outdir()
361361
else:
362362
cachebuilder.outdir = jobcache
363363

cwltool/process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
DependenciesConfiguration)
4646
from .stdfsaccess import StdFsAccess
4747
from .utils import (DEFAULT_TMP_PREFIX, aslist, cmp_like_py2,
48-
copytree_with_merge, onWindows)
48+
copytree_with_merge, onWindows, random_outdir)
4949
from .validate_js import validate_js_expressions
5050
try:
5151
from os import scandir # type: ignore
@@ -644,9 +644,9 @@ def _init_job(self, joborder, runtimeContext):
644644
outdir = dockerReq.get("dockerOutputDirectory")
645645
else:
646646
outdir = dockerReq.get("dockerOutputDirectory") or \
647-
runtimeContext.docker_outdir or "/var/spool/cwl"
647+
runtimeContext.docker_outdir or random_outdir()
648648
elif defaultDocker:
649-
outdir = runtimeContext.docker_outdir or "/var/spool/cwl"
649+
outdir = runtimeContext.docker_outdir or random_outdir()
650650
tmpdir = runtimeContext.docker_tmpdir or "/tmp"
651651
stagedir = runtimeContext.docker_stagedir or "/var/lib/cwl"
652652
else:

cwltool/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import collections
55
import os
66
import platform
7+
import random
78
import shutil
9+
import string
810
import sys
911
from functools import partial # pylint: disable=unused-import
1012
from typing import (IO, Any, AnyStr, Callable, # pylint: disable=unused-import
@@ -209,3 +211,10 @@ def visit_class(rec, cls, op):
209211
if isinstance(rec, MutableSequence):
210212
for d in rec:
211213
visit_class(d, cls, op)
214+
215+
def random_outdir(): # type: () -> Text
216+
""" Return the random directory name chosen to use for tool / workflow output """
217+
# compute this once and store it as a function attribute - each subsequent call will return the same value
218+
if not hasattr(random_outdir, 'outdir'):
219+
random_outdir.outdir = '/' + ''.join([random.choice(string.ascii_letters) for _ in range(6)]) # type: ignore
220+
return random_outdir.outdir # type: ignore

0 commit comments

Comments
 (0)