Spaces:
Running
Running
Update NetworkX wrapper to new Parameter class.
Browse files- 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 |
-
|
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
|
36 |
-
if
|
37 |
-
#
|
38 |
-
if len(
|
39 |
-
|
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
|