diff --git a/pyiron_workflow/mixin/preview.py b/pyiron_workflow/mixin/preview.py index a4c0bf84..41dc8417 100644 --- a/pyiron_workflow/mixin/preview.py +++ b/pyiron_workflow/mixin/preview.py @@ -286,6 +286,38 @@ def _validate_return_count(cls): f"present, " + error_suffix ) + @staticmethod + def _io_defining_documentation(io_defining_function: callable, title: str): + """ + A helper method for building a docstring for classes that have their IO defined + by some function. + """ + try: + signature = str(inspect.signature(io_defining_function)) + except Exception as e: + signature = f"SIGNATURE NOT AVAILABLE -- {type(e).__name__}: {e}" + + try: + source = inspect.getsource(io_defining_function) + except Exception as e: + source = f"SOURCE NOT AVAILABLE -- {type(e).__name__}: {e}" + + doc = ( + "" if io_defining_function.__doc__ is None else io_defining_function.__doc__ + ) + + docs = f"{title.upper()} INFO:\n\n" + docs += "Signature:\n\n" + docs += signature + docs += "\n\n" + docs += "Docstring:\n\n" + docs += doc + docs += "\n" + docs += "Source:\n\n" + docs += source + docs += "\n" + return docs + def no_output_validation_warning(cls: type): return ( diff --git a/pyiron_workflow/nodes/function.py b/pyiron_workflow/nodes/function.py index 84ceafcc..92309db7 100644 --- a/pyiron_workflow/nodes/function.py +++ b/pyiron_workflow/nodes/function.py @@ -380,7 +380,9 @@ def function_node_factory( "__qualname__": node_function.__qualname__, "_output_labels": None if len(output_labels) == 0 else output_labels, "_validate_output_labels": validate_output_labels, - "__doc__": node_function.__doc__, + "__doc__": Function._io_defining_documentation( + node_function, "node_function" + ), "use_cache": use_cache, }, {}, diff --git a/pyiron_workflow/nodes/macro.py b/pyiron_workflow/nodes/macro.py index a16aef28..e193bece 100644 --- a/pyiron_workflow/nodes/macro.py +++ b/pyiron_workflow/nodes/macro.py @@ -494,7 +494,7 @@ def macro_node_factory( "__qualname__": graph_creator.__qualname__, "_output_labels": None if len(output_labels) == 0 else output_labels, "_validate_output_labels": validate_output_labels, - "__doc__": graph_creator.__doc__, + "__doc__": Macro._io_defining_documentation(graph_creator, "graph_creator"), "use_cache": use_cache, }, {},