Skip to content

Commit fa71a8f

Browse files
committed
freshen cwltool/pack.py
1 parent 9ddd07b commit fa71a8f

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

cwltool/pack.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,14 @@
2121
from .context import LoadingContext
2222
from .load_tool import fetch_document, resolve_and_validate_document
2323
from .process import shortname, uniquename
24-
25-
26-
def flatten_deps(d, files): # type: (Any, Set[str]) -> None
27-
if isinstance(d, MutableSequence):
28-
for s in d:
29-
flatten_deps(s, files)
30-
elif isinstance(d, MutableMapping):
31-
if d["class"] == "File":
32-
files.add(d["location"])
33-
if "secondaryFiles" in d:
34-
flatten_deps(d["secondaryFiles"], files)
35-
if "listing" in d:
36-
flatten_deps(d["listing"], files)
37-
24+
from .utils import CWLObjectType, CWLOutputType
3825

3926
LoadRefType = Callable[[Optional[str], str], ResolveType]
4027

4128

4229
def find_run(
43-
d, # type: Any
44-
loadref, # type: LoadRefType
45-
runs, # type: Set[str]
46-
): # type: (...) -> None
30+
d: Union[CWLObjectType, ResolveType], loadref: LoadRefType, runs: Set[str],
31+
) -> None:
4732
if isinstance(d, MutableSequence):
4833
for s in d:
4934
find_run(s, loadref, runs)
@@ -56,16 +41,19 @@ def find_run(
5641
find_run(s, loadref, runs)
5742

5843

59-
def find_ids(d, ids): # type: (Any, Set[str]) -> None
44+
def find_ids(
45+
d: Union[CWLObjectType, CWLOutputType, MutableSequence[CWLObjectType], None],
46+
ids: Set[str],
47+
) -> None:
6048
if isinstance(d, MutableSequence):
6149
for s in d:
62-
find_ids(s, ids)
50+
find_ids(cast(CWLObjectType, s), ids)
6351
elif isinstance(d, MutableMapping):
6452
for i in ("id", "name"):
6553
if i in d and isinstance(d[i], str):
66-
ids.add(d[i])
67-
for s in d.values():
68-
find_ids(s, ids)
54+
ids.add(cast(str, d[i]))
55+
for s2 in d.values():
56+
find_ids(cast(CWLOutputType, s2), ids)
6957

7058

7159
def replace_refs(d: Any, rewrite: Dict[str, str], stem: str, newstem: str) -> None:
@@ -95,34 +83,37 @@ def replace_refs(d: Any, rewrite: Dict[str, str], stem: str, newstem: str) -> No
9583
replace_refs(val, rewrite, stem, newstem)
9684

9785

98-
def import_embed(d, seen):
99-
# type: (Any, Set[str]) -> None
86+
def import_embed(
87+
d: Union[MutableSequence[CWLObjectType], CWLObjectType, CWLOutputType],
88+
seen: Set[str],
89+
) -> None:
10090
if isinstance(d, MutableSequence):
10191
for v in d:
102-
import_embed(v, seen)
92+
import_embed(cast(CWLOutputType, v), seen)
10393
elif isinstance(d, MutableMapping):
10494
for n in ("id", "name"):
10595
if n in d:
10696
if isinstance(d[n], str):
107-
if d[n] in seen:
108-
this = d[n]
97+
ident = cast(str, d[n])
98+
if ident in seen:
99+
this = ident
109100
d.clear()
110101
d["$import"] = this
111102
else:
112-
this = d[n]
103+
this = ident
113104
seen.add(this)
114105
break
115106

116107
for k in sorted(d.keys()):
117-
import_embed(d[k], seen)
108+
import_embed(cast(CWLOutputType, d[k]), seen)
118109

119110

120111
def pack(
121112
loadingContext: LoadingContext,
122-
uri, # type: str
123-
rewrite_out=None, # type: Optional[Dict[str, str]]
124-
loader=None, # type: Optional[Loader]
125-
): # type: (...) -> Dict[str, Any]
113+
uri: str,
114+
rewrite_out: Optional[Dict[str, str]] = None,
115+
loader: Optional[Loader] = None,
116+
) -> CWLObjectType:
126117

127118
# The workflow document we have in memory right now may have been
128119
# updated to the internal CWL version. We need to reload the
@@ -160,8 +151,7 @@ def pack(
160151
document_loader.idx[po["id"]] = CommentedMap(po.items())
161152
document_loader.idx[metadata["id"]] = CommentedMap(metadata.items())
162153

163-
def loadref(base, uri):
164-
# type: (Optional[str], str) -> ResolveType
154+
def loadref(base: Optional[str], uri: str) -> ResolveType:
165155
return document_loader.resolve_ref(uri, base_url=base)[0]
166156

167157
ids = set() # type: Set[str]
@@ -181,8 +171,7 @@ def loadref(base, uri):
181171

182172
mainpath, _ = urllib.parse.urldefrag(uri)
183173

184-
def rewrite_id(r, mainuri):
185-
# type: (str, str) -> None
174+
def rewrite_id(r: str, mainuri: str) -> None:
186175
if r == mainuri:
187176
rewrite[r] = "#main"
188177
elif r.startswith(mainuri) and r[len(mainuri)] in ("#", "/"):

0 commit comments

Comments
 (0)