30
30
31
31
32
32
class AnnotatedVariablesExtractor (ast .NodeTransformer ):
33
+ """AnnotatedVariablesExtractor removes the typing annotations
34
+ from relative to ipython2cwl and identifies all the variables
35
+ relative to an ipython2cwl typing annotation."""
33
36
input_type_mapper : Dict [Tuple [str , ...], Tuple [str , str ]] = {
34
37
(CWLFilePathInput .__name__ ,): (
35
38
'File' ,
@@ -67,11 +70,15 @@ class AnnotatedVariablesExtractor(ast.NodeTransformer):
67
70
}
68
71
69
72
def __init__ (self , * args , ** kwargs ):
73
+ """Create an AnnotatedVariablesExtractor"""
70
74
super ().__init__ (* args , ** kwargs )
71
75
self .extracted_variables : List = []
72
76
self .to_dump : List = []
73
77
74
78
def __get_annotation__ (self , type_annotation ):
79
+ """Parses the annotation and returns it in a canonical format.
80
+ If the annotation was a string 'CWLStringInput' the function
81
+ will return you the object."""
75
82
annotation = None
76
83
if isinstance (type_annotation , ast .Name ):
77
84
annotation = (type_annotation .id ,)
@@ -164,7 +171,8 @@ def visit_AnnAssign(self, node):
164
171
pass
165
172
return node
166
173
167
- def visit_Import (self , node : ast .Import ):
174
+ def visit_Import (self , node : ast .Import ) -> Any :
175
+ """Remove ipython2cwl imports """
168
176
names = []
169
177
for name in node .names : # type: ast.alias
170
178
if name .name == 'ipython2cwl' or name .name .startswith ('ipython2cwl.' ):
@@ -177,6 +185,7 @@ def visit_Import(self, node: ast.Import):
177
185
return None
178
186
179
187
def visit_ImportFrom (self , node : ast .ImportFrom ) -> Any :
188
+ """Remove ipython2cwl imports """
180
189
if node .module == 'ipython2cwl' or (node .module is not None and node .module .startswith ('ipython2cwl.' )):
181
190
return None
182
191
return node
@@ -188,8 +197,7 @@ class AnnotatedIPython2CWLToolConverter:
188
197
with the described inputs & outputs.
189
198
"""
190
199
191
- _code : str
192
- """The annotated python code to convert."""
200
+ _code : str # The annotated python code to convert.
193
201
194
202
def __init__ (self , annotated_ipython_code : str ):
195
203
"""Creates an AnnotatedIPython2CWLToolConverter. If the annotated_ipython_code contains magic commands use the
@@ -198,7 +206,8 @@ def __init__(self, annotated_ipython_code: str):
198
206
self ._code = annotated_ipython_code
199
207
extractor = AnnotatedVariablesExtractor ()
200
208
self ._tree = extractor .visit (ast .parse (self ._code ))
201
- [self ._tree .body .extend (d ) for d in extractor .to_dump ]
209
+ for d in extractor .to_dump :
210
+ self ._tree .body .extend (d )
202
211
self ._tree = ast .fix_missing_locations (self ._tree )
203
212
self ._variables = []
204
213
for variable in extractor .extracted_variables : # type: _VariableNameTypePair
0 commit comments