Skip to content

Commit 649bcdf

Browse files
committed
freshen cwltool/job.py
Remove deref_links which is unused
1 parent d029e07 commit 649bcdf

File tree

2 files changed

+24
-38
lines changed

2 files changed

+24
-38
lines changed

cwltool/job.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import re
77
import shutil
8-
import stat
98
import subprocess # nosec
109
import sys
1110
import tempfile
@@ -17,8 +16,6 @@
1716
from threading import Timer
1817
from typing import (
1918
IO,
20-
Any,
21-
AnyStr,
2219
Callable,
2320
Dict,
2421
Iterable,
@@ -27,6 +24,7 @@
2724
MutableMapping,
2825
MutableSequence,
2926
Optional,
27+
TextIO,
3028
Tuple,
3129
Union,
3230
cast,
@@ -50,7 +48,8 @@
5048
from .utils import (
5149
DEFAULT_TMP_PREFIX,
5250
CWLObjectType,
53-
Directory,
51+
CWLOutputType,
52+
DirectoryType,
5453
OutputCallbackType,
5554
bytes2str_in_dicts,
5655
copytree_with_merge,
@@ -130,21 +129,6 @@
130129
"""
131130

132131

133-
def deref_links(outputs: Any) -> None:
134-
if isinstance(outputs, MutableMapping):
135-
if outputs.get("class") == "File":
136-
st = os.lstat(outputs["path"])
137-
if stat.S_ISLNK(st.st_mode):
138-
outputs["basename"] = os.path.basename(outputs["path"])
139-
outputs["path"] = os.readlink(outputs["path"])
140-
else:
141-
for v in outputs.values():
142-
deref_links(v)
143-
if isinstance(outputs, MutableSequence):
144-
for output in outputs:
145-
deref_links(output)
146-
147-
148132
def relink_initialworkdir(
149133
pathmapper: PathMapper,
150134
host_outdir: str,
@@ -192,6 +176,9 @@ def neverquote(string: str, pos: int = 0, endpos: int = 0) -> Optional[Match[str
192176
return None
193177

194178

179+
CollectOutputsType = Union[Callable[[str, int], CWLObjectType], functools.partial]
180+
181+
195182
class JobBase(HasReqsHints, metaclass=ABCMeta):
196183
def __init__(
197184
self,
@@ -221,9 +208,7 @@ def __init__(
221208
self.generatemapper = None # type: Optional[PathMapper]
222209

223210
# set in CommandLineTool.job(i)
224-
self.collect_outputs = cast(
225-
Callable[[str, int], MutableMapping[str, Any]], None
226-
) # type: Union[Callable[[str, int], MutableMapping[str, Any]], functools.partial[MutableMapping[str, Any]]]
211+
self.collect_outputs = cast(CollectOutputsType, None)
227212
self.output_callback = None # type: Optional[OutputCallbackType]
228213
self.outdir = ""
229214
self.tmpdir = ""
@@ -233,7 +218,7 @@ def __init__(
233218
"class": "Directory",
234219
"listing": [],
235220
"basename": "",
236-
} # type: Directory
221+
} # type: DirectoryType
237222
self.stagedir = None # type: Optional[str]
238223
self.inplace_update = False
239224
self.prov_obj = None # type: Optional[ProvenanceProfile]
@@ -269,7 +254,7 @@ def _setup(self, runtimeContext: RuntimeContext) -> None:
269254
runtimeContext = runtimeContext.copy()
270255
runtimeContext.outdir = self.outdir
271256
self.generatemapper = self.make_path_mapper(
272-
cast(List[Any], self.generatefiles["listing"]),
257+
self.generatefiles["listing"],
273258
self.builder.outdir,
274259
runtimeContext,
275260
False,
@@ -331,7 +316,7 @@ def _execute(
331316
"or prov_obj is missing from runtimeContext: "
332317
"{}".format(runtimeContext)
333318
)
334-
outputs = {} # type: MutableMapping[str,Any]
319+
outputs = {} # type: CWLObjectType
335320
try:
336321
stdin_path = None
337322
if self.stdin is not None:
@@ -361,8 +346,14 @@ def _execute(
361346

362347
commands = [str(x) for x in runtime + self.command_line]
363348
if runtimeContext.secret_store is not None:
364-
commands = runtimeContext.secret_store.retrieve(commands)
365-
env = runtimeContext.secret_store.retrieve(env)
349+
commands = cast(
350+
List[str],
351+
runtimeContext.secret_store.retrieve(cast(CWLOutputType, commands)),
352+
)
353+
env = cast(
354+
MutableMapping[str, str],
355+
runtimeContext.secret_store.retrieve(cast(CWLOutputType, env)),
356+
)
366357

367358
job_script_contents = None # type: Optional[str]
368359
builder = getattr(self, "builder", None) # type: Builder
@@ -653,10 +644,9 @@ def create_file_and_add_volume(
653644
os.path.basename(volume.target),
654645
)
655646
writable = True if volume.type == "CreateWritableFile" else False
647+
contents = volume.resolved
656648
if secret_store:
657-
contents = secret_store.retrieve(volume.resolved)
658-
else:
659-
contents = volume.resolved
649+
contents = cast(str, secret_store.retrieve(volume.resolved))
660650
dirname = os.path.dirname(host_outdir_tgt or new_file)
661651
if not os.path.exists(dirname):
662652
os.makedirs(dirname)
@@ -918,15 +908,15 @@ def _job_popen(
918908

919909
if job_script_contents is None and not FORCE_SHELLED_POPEN:
920910

921-
stdin = subprocess.PIPE # type: Union[IO[Any], int]
911+
stdin = subprocess.PIPE # type: Union[IO[bytes], int]
922912
if stdin_path is not None:
923913
stdin = open(stdin_path, "rb")
924914

925-
stdout = sys.stderr # type: IO[Any]
915+
stdout = sys.stderr # type: Union[IO[bytes], TextIO]
926916
if stdout_path is not None:
927917
stdout = open(stdout_path, "wb")
928918

929-
stderr = sys.stderr # type: IO[Any]
919+
stderr = sys.stderr # type: Union[IO[bytes], TextIO]
930920
if stderr_path is not None:
931921
stderr = open(stderr_path, "wb")
932922

@@ -986,7 +976,7 @@ def terminate(): # type: () -> None
986976
job_script_contents = SHELL_COMMAND_TEMPLATE
987977

988978
env_copy = {}
989-
key = None # type: Any
979+
key = None # type: Optional[str]
990980
for key in env:
991981
env_copy[key] = env[key]
992982

cwltool/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555

5656
windows_default_container_id = "frolvlad/alpine-bash"
5757

58-
Directory = TypedDict(
59-
"Directory", {"class": str, "listing": List[Dict[str, Any]], "basename": str}
60-
)
61-
6258
DEFAULT_TMP_PREFIX = tempfile.gettempdir() + os.path.sep
6359

6460
processes_to_kill = collections.deque() # type: Deque[subprocess.Popen[str]]

0 commit comments

Comments
 (0)