Skip to content

Commit bf58b01

Browse files
committed
WID-100. Fix after rebase.
1 parent 879f231 commit bf58b01

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

xircuits/handlers/component_parser.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
# A good point in time to do that, would be when the python compilation step
2222
# gets refactored
2323
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"},
3636
# Comment this first since we don't use it
3737
# 1: { "name": "Math Operation", "returnType": "math"},
3838
# 2: { "name": "Convert to Aurora", "returnType": "convert"},
@@ -99,7 +99,8 @@ def get_components(self):
9999
"header": GROUP_GENERAL,
100100
"category": GROUP_GENERAL,
101101
"variables": [],
102-
"type": c["returnType"]
102+
"type": c["returnType"],
103+
"color": c.get('color') or None
103104
})
104105

105106
default_paths = set(pathlib.Path(p).expanduser().resolve() for p in sys.path)
@@ -127,7 +128,6 @@ def get_components(self):
127128
finally:
128129
components.extend(chain.from_iterable(self.extract_components(f, directory, python_path) for f in python_files))
129130

130-
131131
components = list({(c["header"], c["task"]): c for c in components}.values())
132132
return components
133133

@@ -176,28 +176,29 @@ def extract_component(self, node: ast.ClassDef, file_path, file_lines, python_pa
176176

177177
is_arg = lambda n: isinstance(n, ast.AnnAssign) and \
178178
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']
180184

181185
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({
185191
"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({
194197
"name": v.target.id,
195198
"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
201202

202203
docstring = ast.get_docstring(node)
203204
lineno = [

xircuits/handlers/components.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import tornado
32
from jupyter_server.base.handlers import APIHandler
43
from .component_parser import ComponentsParser

0 commit comments

Comments
 (0)