Skip to content

Commit d761613

Browse files
committed
cleaned up print_help
1 parent 8906e8f commit d761613

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pydra/engine/helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def print_help(defn: "TaskDef[DefType]") -> list[str]:
8686
if list_fields(defn):
8787
lines += ["Input Parameters:"]
8888
for f in list_fields(defn):
89+
if (defn._task_type == "python" and f.name == "function") or (
90+
defn._task_type == "workflow" and f.name == "constructor"
91+
):
92+
continue
8993
default = ""
9094
if f.default is not EMPTY and not f.name.startswith("_"):
9195
default = f" (default: {f.default})"

pydra/engine/tests/test_task.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def test_checksum():
6666

6767
def test_annotated_func():
6868
@python.define(outputs=["out_out"])
69-
def testfunc(a: int, b: float = 0.1) -> float:
69+
def TestFunc(a: int, b: float = 0.1) -> float:
7070
return a + b
7171

72-
funky = testfunc(a=1)
72+
funky = TestFunc(a=1)
7373
assert hasattr(funky, "a")
7474
assert hasattr(funky, "b")
7575
assert hasattr(funky, "function")
@@ -92,11 +92,10 @@ def testfunc(a: int, b: float = 0.1) -> float:
9292

9393
help = print_help(funky)
9494
assert help == [
95-
"Help for PythonTask",
95+
"Help for TestFunc",
9696
"Input Parameters:",
9797
"- a: int",
9898
"- b: float (default: 0.1)",
99-
"- _func: bytes",
10099
"Output Parameters:",
101100
"- out_out: float",
102101
]
@@ -125,36 +124,35 @@ def testfunc(a: int, b: int):
125124
def test_annotated_func_multreturn():
126125
"""the function has two elements in the return statement"""
127126

128-
@python.define
129-
def testfunc(
127+
@python.define(outputs={"fractional": float, "integer": int})
128+
def TestFunc(
130129
a: float,
131-
) -> ty.NamedTuple("Output", [("fractional", float), ("integer", int)]):
130+
):
132131
import math
133132

134133
return math.modf(a)[0], int(math.modf(a)[1])
135134

136-
funky = testfunc(a=3.5)
135+
funky = TestFunc(a=3.5)
137136
assert hasattr(funky, "a")
138-
assert hasattr(funky, "_func")
137+
assert hasattr(funky, "function")
139138
assert getattr(funky, "a") == 3.5
140-
assert getattr(funky, "_func") is not None
141-
assert set(funky.output_names) == {"fractional", "integer"}
142-
assert funky.__class__.__name__ + "_" + funky.hash == funky.checksum
139+
assert getattr(funky, "function") is not None
140+
assert set(f.name for f in list_fields(funky.Outputs)) == {"fractional", "integer"}
143141

144142
outputs = funky()
145-
assert os.path.exists(funky.cache_dir / funky.checksum / "_result.pklz")
146-
assert hasattr(result, "output")
143+
assert os.path.exists(
144+
default_run_cache_dir / f"python-{funky._hash}" / "_result.pklz"
145+
)
147146
assert hasattr(outputs, "fractional")
148147
assert outputs.fractional == 0.5
149148
assert hasattr(outputs, "integer")
150149
assert outputs.integer == 3
151150

152-
help = funky.help(returnhelp=True)
151+
help = print_help(funky)
153152
assert help == [
154-
"Help for PythonTask",
153+
"Help for TestFunc",
155154
"Input Parameters:",
156155
"- a: float",
157-
"- _func: bytes",
158156
"Output Parameters:",
159157
"- fractional: float",
160158
"- integer: int",

0 commit comments

Comments
 (0)