Skip to content

Commit ef4cfe2

Browse files
committed
fix types
1 parent 42fde01 commit ef4cfe2

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

cwltool/docker.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .errors import WorkflowException
2121
from .job import ContainerCommandLineJob
2222
from .loghandler import _logger
23-
from .pathmapper import PathMapper # pylint: disable=unused-import
23+
from .pathmapper import PathMapper, MapperEnt # pylint: disable=unused-import
2424
from .pathmapper import ensure_writable, ensure_non_writable
2525
from .secrets import SecretStore # pylint: disable=unused-import
2626
from .utils import (DEFAULT_TMP_PREFIX, docker_windows_path_adjust, onWindows,
@@ -219,7 +219,7 @@ def append_volume(runtime, source, target, writable=False):
219219
def add_file_or_directory_volume(self,
220220
runtime, # type: List[Text]
221221
volume, # type: MapperEnt
222-
host_outdir_tgt # type: Text
222+
host_outdir_tgt # type: Optional[Text]
223223
): # type: (...) -> None
224224
"""Append volume a file/dir mapping to the runtime option list."""
225225
if not volume.resolved.startswith("_:"):
@@ -230,7 +230,7 @@ def add_file_or_directory_volume(self,
230230
def add_writable_file_volume(self,
231231
runtime, # type: List[Text]
232232
volume, # type: MapperEnt
233-
host_outdir_tgt # type: Text
233+
host_outdir_tgt # type: Optional[Text]
234234
): # type: (...) -> None
235235
"""Append a writable file mapping to the runtime option list."""
236236
if self.inplace_update:
@@ -253,7 +253,7 @@ def add_writable_file_volume(self,
253253
def add_writable_directory_volume(self,
254254
runtime, # type: List[Text]
255255
volume, # type: MapperEnt
256-
host_outdir_tgt # type: Text
256+
host_outdir_tgt # type: Optional[Text]
257257
): # type: (...) -> None
258258
"""Append a writable directory mapping to the runtime option list."""
259259
if volume.resolved.startswith("_:"):
@@ -273,19 +273,20 @@ def add_writable_directory_volume(self,
273273
else:
274274
if not host_outdir_tgt:
275275
tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
276-
host_outdir_tgt = os.path.join(
276+
new_dir = os.path.join(
277277
tmpdir, os.path.basename(volume.resolved))
278-
shutil.copytree(volume.resolved, host_outdir_tgt)
278+
shutil.copytree(volume.resolved, new_dir)
279279
self.append_volume(
280-
runtime, host_outdir_tgt, volume.target,
280+
runtime, new_dir, volume.target,
281281
writable=True)
282282
else:
283283
shutil.copytree(volume.resolved, host_outdir_tgt)
284-
ensure_writable(host_outdir_tgt)
284+
ensure_writable(host_outdir_tgt or new_dir)
285285

286286
def create_runtime(self, env, runtimeContext):
287287
# type: (MutableMapping[Text, Text], RuntimeContext) -> List
288-
any_path_okay = self.builder.get_requirement("DockerRequirement")[1]
288+
any_path_okay = self.builder.get_requirement("DockerRequirement")[1] \
289+
or False
289290
user_space_docker_cmd = runtimeContext.user_space_docker_cmd
290291
if user_space_docker_cmd:
291292
if 'udocker' in user_space_docker_cmd and not runtimeContext.debug:

cwltool/job.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def append_volume(runtime, source, target, writable=False):
454454
def add_file_or_directory_volume(self,
455455
runtime, # type: List[Text]
456456
volume, # type: MapperEnt
457-
host_outdir_tgt # type: Text
457+
host_outdir_tgt # type: Optional[Text]
458458
): # type: (...) -> None
459459
"""Append volume a file/dir mapping to the runtime option list."""
460460
pass
@@ -463,7 +463,7 @@ def add_file_or_directory_volume(self,
463463
def add_writable_file_volume(self,
464464
runtime, # type: List[Text]
465465
volume, # type: MapperEnt
466-
host_outdir_tgt # type: Text
466+
host_outdir_tgt # type: Optional[Text]
467467
): # type: (...) -> None
468468
"""Append a writable file mapping to the runtime option list."""
469469
pass
@@ -472,41 +472,39 @@ def add_writable_file_volume(self,
472472
def add_writable_directory_volume(self,
473473
runtime, # type: List[Text]
474474
volume, # type: MapperEnt
475-
host_outdir_tgt # type: Text
475+
host_outdir_tgt # type: Optional[Text]
476476
): # type: (...) -> None
477477
"""Append a writable directory mapping to the runtime option list."""
478478
pass
479479

480480
def create_file_and_add_volume(self,
481481
runtime, # type: List[Text]
482482
volume, # type: MapperEnt
483-
host_outdir_tgt, # type: Text
484-
secret_store # type: SecretStore
483+
host_outdir_tgt, # type: Optional[Text]
484+
secret_store # type: Optional[SecretStore]
485485
): # type: (...) -> None
486486
"""Create the file and add a mapping."""
487487
if not host_outdir_tgt:
488-
tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
489-
host_outdir_tgt = os.path.join(
490-
tmpdir, os.path.basename(volume.resolved))
491-
else:
492-
tmpdir = False
488+
new_file = os.path.join(
489+
tempfile.mkdtemp(dir=self.tmpdir),
490+
os.path.basename(volume.resolved))
493491
writable = True if volume.type == "CreateWritableFile" else False
494492
if secret_store:
495493
contents = secret_store.retrieve(volume.resolved)
496494
else:
497495
contents = volume.resolved
498-
dirname = os.path.dirname(host_outdir_tgt)
496+
dirname = os.path.dirname(host_outdir_tgt or new_file)
499497
if not os.path.exists(dirname):
500498
os.makedirs(dirname, 0o0755)
501-
with open(host_outdir_tgt, "wb") as file_literal:
499+
with open(host_outdir_tgt or new_file, "wb") as file_literal:
502500
file_literal.write(contents.encode("utf-8"))
503-
if not tmpdir:
504-
self.append_volume(runtime, host_outdir_tgt, volume.target,
501+
if new_file:
502+
self.append_volume(runtime, new_file, volume.target,
505503
writable=writable)
506504
if writable:
507-
ensure_writable(host_outdir_tgt)
505+
ensure_writable(host_outdir_tgt or new_file)
508506
else:
509-
ensure_non_writable(host_outdir_tgt)
507+
ensure_non_writable(host_outdir_tgt or new_file)
510508

511509

512510

cwltool/singularity.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .errors import WorkflowException
1919
from .job import ContainerCommandLineJob
2020
from .loghandler import _logger
21-
from .pathmapper import PathMapper # pylint: disable=unused-import
21+
from .pathmapper import PathMapper, MapperEnt # pylint: disable=unused-import
2222
from .pathmapper import ensure_writable, ensure_non_writable
2323
from .process import UnsupportedRequirement
2424
from .utils import docker_windows_path_adjust
@@ -160,6 +160,7 @@ def get_from_requirements(self,
160160

161161
@staticmethod
162162
def append_volume(runtime, source, target, writable=False):
163+
# type: (List[Text], Text, Text, bool) -> None
163164
runtime.append(u"--bind")
164165
runtime.append("{}:{}:{}".format(
165166
docker_windows_path_adjust(source),
@@ -168,7 +169,7 @@ def append_volume(runtime, source, target, writable=False):
168169
def add_file_or_directory_volume(self,
169170
runtime, # type: List[Text]
170171
volume, # type: MapperEnt
171-
host_outdir_tgt # type: Text
172+
host_outdir_tgt # type: Optional[Text]
172173
): # type: (...) -> None
173174
if host_outdir_tgt:
174175
# workaround for lack of overlapping mounts in Singularity
@@ -186,7 +187,7 @@ def add_file_or_directory_volume(self,
186187
def add_writable_file_volume(self,
187188
runtime, # type: List[Text]
188189
volume, # type: MapperEnt
189-
host_outdir_tgt # type: Text
190+
host_outdir_tgt # type: Optional[Text]
190191
): # type: (...) -> None
191192
if host_outdir_tgt:
192193
# workaround for lack of overlapping mounts in Singularity
@@ -219,7 +220,7 @@ def add_writable_file_volume(self,
219220
def add_writable_directory_volume(self,
220221
runtime, # type: List[Text]
221222
volume, # type: MapperEnt
222-
host_outdir_tgt # type: Text
223+
host_outdir_tgt # type: Optional[Text]
223224
): # type: (...) -> None
224225
if volume.resolved.startswith("_:"):
225226
if host_outdir_tgt:
@@ -258,7 +259,8 @@ def create_runtime(self,
258259
):
259260
# type: (...) -> List
260261
""" Returns the Singularity runtime list of commands and options."""
261-
any_path_okay = self.builder.get_requirement("DockerRequirement")[1]
262+
any_path_okay = self.builder.get_requirement("DockerRequirement")[1] \
263+
or False
262264
runtime = [u"singularity", u"--quiet", u"exec", u"--contain", u"--pid",
263265
u"--ipc"]
264266
if _singularity_supports_userns():

tests/test_secrets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import pytest
55
from cwltool.secrets import SecretStore
66
from cwltool.main import main
7-
from .util import get_data, needs_docker, needs_singularity
7+
from .util import (get_data, needs_docker, needs_singularity,
8+
windows_needs_docker)
89
if sys.version_info[0] < 3:
910
from io import BytesIO as TextIO
1011
else:
@@ -66,6 +67,7 @@ def test_secret_workflow_log_singularity():
6667
shutil.rmtree(tmpdir)
6768
assert "Hoopla!" not in stream.getvalue()
6869

70+
@windows_needs_docker
6971
def test_secret_workflow_log_override():
7072
stream = TextIO()
7173
tmpdir = tempfile.mkdtemp()

0 commit comments

Comments
 (0)