21
21
from .context import LoadingContext
22
22
from .load_tool import fetch_document , resolve_and_validate_document
23
23
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
38
25
39
26
LoadRefType = Callable [[Optional [str ], str ], ResolveType ]
40
27
41
28
42
29
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 :
47
32
if isinstance (d , MutableSequence ):
48
33
for s in d :
49
34
find_run (s , loadref , runs )
@@ -56,16 +41,19 @@ def find_run(
56
41
find_run (s , loadref , runs )
57
42
58
43
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 :
60
48
if isinstance (d , MutableSequence ):
61
49
for s in d :
62
- find_ids (s , ids )
50
+ find_ids (cast ( CWLObjectType , s ) , ids )
63
51
elif isinstance (d , MutableMapping ):
64
52
for i in ("id" , "name" ):
65
53
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 )
69
57
70
58
71
59
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
95
83
replace_refs (val , rewrite , stem , newstem )
96
84
97
85
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 :
100
90
if isinstance (d , MutableSequence ):
101
91
for v in d :
102
- import_embed (v , seen )
92
+ import_embed (cast ( CWLOutputType , v ) , seen )
103
93
elif isinstance (d , MutableMapping ):
104
94
for n in ("id" , "name" ):
105
95
if n in d :
106
96
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
109
100
d .clear ()
110
101
d ["$import" ] = this
111
102
else :
112
- this = d [ n ]
103
+ this = ident
113
104
seen .add (this )
114
105
break
115
106
116
107
for k in sorted (d .keys ()):
117
- import_embed (d [k ], seen )
108
+ import_embed (cast ( CWLOutputType , d [k ]) , seen )
118
109
119
110
120
111
def pack (
121
112
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 :
126
117
127
118
# The workflow document we have in memory right now may have been
128
119
# updated to the internal CWL version. We need to reload the
@@ -160,8 +151,7 @@ def pack(
160
151
document_loader .idx [po ["id" ]] = CommentedMap (po .items ())
161
152
document_loader .idx [metadata ["id" ]] = CommentedMap (metadata .items ())
162
153
163
- def loadref (base , uri ):
164
- # type: (Optional[str], str) -> ResolveType
154
+ def loadref (base : Optional [str ], uri : str ) -> ResolveType :
165
155
return document_loader .resolve_ref (uri , base_url = base )[0 ]
166
156
167
157
ids = set () # type: Set[str]
@@ -181,8 +171,7 @@ def loadref(base, uri):
181
171
182
172
mainpath , _ = urllib .parse .urldefrag (uri )
183
173
184
- def rewrite_id (r , mainuri ):
185
- # type: (str, str) -> None
174
+ def rewrite_id (r : str , mainuri : str ) -> None :
186
175
if r == mainuri :
187
176
rewrite [r ] = "#main"
188
177
elif r .startswith (mainuri ) and r [len (mainuri )] in ("#" , "/" ):
0 commit comments