Spaces:
Running
Running
Merge pull request #200 from biggraph/darabos-griffe
Browse filesFix Griffe warnings, requirements.txt, and an improved error message
examples/requirements.txt
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
# Example of a requirements.txt file. LynxKite will automatically install anything you put here.
|
2 |
faker
|
3 |
matplotlib
|
4 |
-
chembl_webresource_client
|
5 |
-
rcsb-api
|
6 |
-
itertools
|
|
|
1 |
# Example of a requirements.txt file. LynxKite will automatically install anything you put here.
|
2 |
faker
|
3 |
matplotlib
|
|
|
|
|
|
lynxkite-core/src/lynxkite/core/ops.py
CHANGED
@@ -247,7 +247,7 @@ def op(
|
|
247 |
"""Decorator for defining an operation."""
|
248 |
|
249 |
def decorator(func):
|
250 |
-
doc = parse_doc(func
|
251 |
sig = inspect.signature(func)
|
252 |
_view = view
|
253 |
if view == "matplotlib":
|
@@ -444,16 +444,45 @@ def run_user_script(script_path: pathlib.Path):
|
|
444 |
|
445 |
|
446 |
@functools.cache
|
447 |
-
def parse_doc(
|
448 |
-
"""Griffe is an optional dependency. When available, we
|
|
|
449 |
try:
|
450 |
import griffe
|
451 |
except ImportError:
|
452 |
return doc
|
453 |
if doc is None:
|
454 |
return None
|
|
|
455 |
if "----" in doc:
|
456 |
-
|
457 |
else:
|
458 |
-
|
459 |
-
return json.loads(json.dumps(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
"""Decorator for defining an operation."""
|
248 |
|
249 |
def decorator(func):
|
250 |
+
doc = parse_doc(func)
|
251 |
sig = inspect.signature(func)
|
252 |
_view = view
|
253 |
if view == "matplotlib":
|
|
|
444 |
|
445 |
|
446 |
@functools.cache
|
447 |
+
def parse_doc(func):
|
448 |
+
"""Griffe is an optional dependency. When available, we return the parsed docstring."""
|
449 |
+
doc = func.__doc__
|
450 |
try:
|
451 |
import griffe
|
452 |
except ImportError:
|
453 |
return doc
|
454 |
if doc is None:
|
455 |
return None
|
456 |
+
ds = griffe.Docstring(doc, parent=_get_griffe_function(func))
|
457 |
if "----" in doc:
|
458 |
+
ds = ds.parse("numpy")
|
459 |
else:
|
460 |
+
ds = ds.parse("google")
|
461 |
+
return json.loads(json.dumps(ds, cls=griffe.JSONEncoder))
|
462 |
+
|
463 |
+
|
464 |
+
def _get_griffe_function(func):
|
465 |
+
"""Returns a griffe.Function object based on the signature of the function."""
|
466 |
+
import griffe
|
467 |
+
|
468 |
+
sig = inspect.signature(func)
|
469 |
+
parameters = []
|
470 |
+
for name, param in sig.parameters.items():
|
471 |
+
if param.annotation is inspect.Parameter.empty:
|
472 |
+
annotation = None
|
473 |
+
else:
|
474 |
+
annotation = param.annotation.__name__
|
475 |
+
parameters.append(
|
476 |
+
griffe.Parameter(
|
477 |
+
name,
|
478 |
+
annotation=annotation,
|
479 |
+
kind=griffe.ParameterKind.keyword_only
|
480 |
+
if param.kind == inspect.Parameter.KEYWORD_ONLY
|
481 |
+
else griffe.ParameterKind.positional_or_keyword,
|
482 |
+
)
|
483 |
+
)
|
484 |
+
return griffe.Function(
|
485 |
+
func.__name__,
|
486 |
+
parameters=griffe.Parameters(*parameters),
|
487 |
+
returns=str(sig.return_annotation),
|
488 |
+
)
|
lynxkite-graph-analytics/src/lynxkite_graph_analytics/core.py
CHANGED
@@ -224,12 +224,16 @@ async def _execute_node(
|
|
224 |
missing.append(p.name)
|
225 |
continue
|
226 |
x = input_map[p.name]
|
227 |
-
if p.type == nx.Graph
|
228 |
-
x
|
229 |
-
|
230 |
-
x
|
231 |
-
elif p.type == Bundle
|
232 |
-
x
|
|
|
|
|
|
|
|
|
233 |
inputs.append(x)
|
234 |
except Exception as e:
|
235 |
if not os.environ.get("LYNXKITE_SUPPRESS_OP_ERRORS"):
|
|
|
224 |
missing.append(p.name)
|
225 |
continue
|
226 |
x = input_map[p.name]
|
227 |
+
if p.type == nx.Graph:
|
228 |
+
if isinstance(x, Bundle):
|
229 |
+
x = x.to_nx()
|
230 |
+
assert isinstance(x, nx.Graph), "Input must be a graph."
|
231 |
+
elif p.type == Bundle:
|
232 |
+
if isinstance(x, nx.Graph):
|
233 |
+
x = Bundle.from_nx(x)
|
234 |
+
elif isinstance(x, pd.DataFrame):
|
235 |
+
x = Bundle.from_df(x)
|
236 |
+
assert isinstance(x, Bundle), "Input must be a graph or dataframe."
|
237 |
inputs.append(x)
|
238 |
except Exception as e:
|
239 |
if not os.environ.get("LYNXKITE_SUPPRESS_OP_ERRORS"):
|
lynxkite-graph-analytics/src/lynxkite_graph_analytics/lynxkite_ops.py
CHANGED
@@ -303,7 +303,7 @@ def create_graph(bundle: core.Bundle, *, relations: str = None) -> core.Bundle:
|
|
303 |
relations (str, optional): Set of relations to set for the bundle. The parameter
|
304 |
should be a JSON object where the keys are relation names and the values are
|
305 |
a dictionary representation of a `RelationDefinition`.
|
306 |
-
|
307 |
|
308 |
Returns:
|
309 |
Bundle: The input bundle with the new relations set.
|
|
|
303 |
relations (str, optional): Set of relations to set for the bundle. The parameter
|
304 |
should be a JSON object where the keys are relation names and the values are
|
305 |
a dictionary representation of a `RelationDefinition`.
|
306 |
+
Defaults to None.
|
307 |
|
308 |
Returns:
|
309 |
Bundle: The input bundle with the new relations set.
|