darabos commited on
Commit
36446e3
·
1 Parent(s): 111a829

Update NetworkX wrapper to new Parameter class.

Browse files
Files changed (1) hide show
  1. server/networkx_ops.py +9 -8
server/networkx_ops.py CHANGED
@@ -26,17 +26,18 @@ for (name, func) in nx.__dict__.items():
26
  sig = inspect.signature(func)
27
  inputs = {k: nx.Graph for k in func.graphs}
28
  params = {
29
- name:
30
- str(param.default)
31
  if type(param.default) in [str, int, float]
32
- else None
 
33
  for name, param in sig.parameters.items()
34
  if name not in ['G', 'backend', 'backend_kwargs']}
35
- for k, v in params.items():
36
- if sig.parameters[k].annotation is inspect._empty and v is None:
37
- # No annotation, no default — we must guess the type.
38
- if len(k) == 1:
39
- params[k] = 1
40
  name = "NX › " + name.replace('_', ' ').title()
41
  op = ops.Op(wrapped(func), name, params=params, inputs=inputs, outputs={'output': 'yes'}, type='basic')
42
  ops.ALL_OPS[name] = op
 
26
  sig = inspect.signature(func)
27
  inputs = {k: nx.Graph for k in func.graphs}
28
  params = {
29
+ name: ops.Parameter(
30
+ name, str(param.default)
31
  if type(param.default) in [str, int, float]
32
+ else None,
33
+ param.annotation)
34
  for name, param in sig.parameters.items()
35
  if name not in ['G', 'backend', 'backend_kwargs']}
36
+ for p in params.values():
37
+ if not p.type:
38
+ # Guess the type based on the name.
39
+ if len(p.name) == 1:
40
+ p.type = int
41
  name = "NX › " + name.replace('_', ' ').title()
42
  op = ops.Op(wrapped(func), name, params=params, inputs=inputs, outputs={'output': 'yes'}, type='basic')
43
  ops.ALL_OPS[name] = op