|
21 | 21 | # A good point in time to do that, would be when the python compilation step |
22 | 22 | # gets refactored |
23 | 23 | DEFAULT_COMPONENTS = { |
24 | | - 1: { "name": "Get Hyper-parameter String Name", "returnType": "string"}, |
25 | | - 2: { "name": "Get Hyper-parameter Int Name", "returnType": "int"}, |
26 | | - 3: { "name": "Get Hyper-parameter Float Name", "returnType": "float"}, |
27 | | - 4: { "name": "Get Hyper-parameter Boolean Name", "returnType": "boolean"}, |
28 | | - 5: { "name": "Literal String", "returnType": "string"}, |
29 | | - 6:{ "name": "Literal Integer", "returnType": "int"}, |
30 | | - 7:{ "name": "Literal Float", "returnType": "float"}, |
31 | | - 8:{ "name": "Literal True", "returnType": "boolean"}, |
32 | | - 9:{ "name": "Literal False", "returnType": "boolean"}, |
33 | | - 10:{ "name": "Literal List", "returnType": "list"}, |
34 | | - 11:{ "name": "Literal Tuple", "returnType": "tuple"}, |
35 | | - 12:{ "name": "Literal Dict", "returnType": "dict"}, |
| 24 | + 1: { "name": "Get Argument String Name", "returnType": "string","color":"lightpink"}, |
| 25 | + 2: { "name": "Get Argument Integer Name", "returnType": "int","color":"blue"}, |
| 26 | + 3: { "name": "Get Argument Float Name", "returnType": "float","color":"green"}, |
| 27 | + 4: { "name": "Get Argument Boolean Name", "returnType": "boolean","color":"red"}, |
| 28 | + 5: { "name": "Literal String", "returnType": "string","color":"lightpink"}, |
| 29 | + 6:{ "name": "Literal Integer", "returnType": "int","color":"blue"}, |
| 30 | + 7:{ "name": "Literal Float", "returnType": "float","color":"green"}, |
| 31 | + 8:{ "name": "Literal True", "returnType": "boolean","color":"red"}, |
| 32 | + 9:{ "name": "Literal False", "returnType": "boolean","color":"red"}, |
| 33 | + 10:{ "name": "Literal List", "returnType": "list","color":"yellow"}, |
| 34 | + 11:{ "name": "Literal Tuple", "returnType": "tuple","color":"purple"}, |
| 35 | + 12:{ "name": "Literal Dict", "returnType": "dict","color":"orange"}, |
36 | 36 | # Comment this first since we don't use it |
37 | 37 | # 1: { "name": "Math Operation", "returnType": "math"}, |
38 | 38 | # 2: { "name": "Convert to Aurora", "returnType": "convert"}, |
@@ -99,7 +99,8 @@ def get_components(self): |
99 | 99 | "header": GROUP_GENERAL, |
100 | 100 | "category": GROUP_GENERAL, |
101 | 101 | "variables": [], |
102 | | - "type": c["returnType"] |
| 102 | + "type": c["returnType"], |
| 103 | + "color": c.get('color') or None |
103 | 104 | }) |
104 | 105 |
|
105 | 106 | default_paths = set(pathlib.Path(p).expanduser().resolve() for p in sys.path) |
@@ -127,7 +128,6 @@ def get_components(self): |
127 | 128 | finally: |
128 | 129 | components.extend(chain.from_iterable(self.extract_components(f, directory, python_path) for f in python_files)) |
129 | 130 |
|
130 | | - |
131 | 131 | components = list({(c["header"], c["task"]): c for c in components}.values()) |
132 | 132 | return components |
133 | 133 |
|
@@ -176,28 +176,29 @@ def extract_component(self, node: ast.ClassDef, file_path, file_lines, python_pa |
176 | 176 |
|
177 | 177 | is_arg = lambda n: isinstance(n, ast.AnnAssign) and \ |
178 | 178 | isinstance(n.annotation, ast.Subscript) and \ |
179 | | - n.annotation.value.id in ('InArg', 'InCompArg', 'OutArg') |
| 179 | + n.annotation.value.id in ['InArg', 'InCompArg', 'OutArg'] |
| 180 | + |
| 181 | + is_flow_arg = lambda n: isinstance(n, ast.AnnAssign) and \ |
| 182 | + isinstance(n.annotation, ast.Name) and \ |
| 183 | + n.annotation.id in ['BaseComponent'] |
180 | 184 |
|
181 | 185 | python_version = platform.python_version_tuple() |
182 | | - if int(python_version[1]) == 8: |
183 | | - variables = [ |
184 | | - { |
| 186 | + |
| 187 | + variables = [] |
| 188 | + for v in (node.body): |
| 189 | + if is_flow_arg(v): |
| 190 | + variables.append({ |
185 | 191 | "name": v.target.id, |
186 | | - "kind": v.annotation.value.id, |
187 | | - "type": read_orig_code(v.annotation.slice.value, file_lines) |
188 | | - } |
189 | | - for v in node.body if is_arg(v) |
190 | | - ] |
191 | | - else: |
192 | | - variables = [ |
193 | | - { |
| 192 | + "kind": v.annotation.id, |
| 193 | + }) |
| 194 | + continue |
| 195 | + elif is_arg(v): |
| 196 | + variables.append({ |
194 | 197 | "name": v.target.id, |
195 | 198 | "kind": v.annotation.value.id, |
196 | | - # "type": ast.unparse(v.annotation.slice) |
197 | | - "type": read_orig_code(v.annotation.slice, file_lines) |
198 | | - } |
199 | | - for v in node.body if is_arg(v) |
200 | | - ] |
| 199 | + "type": read_orig_code(v.annotation.slice.value if int(python_version[1]) == 8 else v.annotation.slice, file_lines) |
| 200 | + }) |
| 201 | + continue |
201 | 202 |
|
202 | 203 | docstring = ast.get_docstring(node) |
203 | 204 | lineno = [ |
|
0 commit comments