Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_cli_with_partials():
work.function = "workflow.examples.function.cli"
work.parameters = {"alpha": 5}
work = execute.function(work)
results, products, plots = math(alpha=5, beta=2)
results, products, plots = math(alpha=5)
assert work.results == results
assert work.products == products
assert work.plots == plots
Expand Down
7 changes: 3 additions & 4 deletions workflow/examples/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ def worker(work: Work) -> Work:
@click.option(
"--alpha",
"-a",
default=1.0,
type=FirstOf(click.FLOAT, click.INT),
required=True,
help="A number.",
)
@click.option(
"--beta",
"-b",
default=2.0,
default=1,
type=FirstOf(click.FLOAT, click.INT),
required=True,
required=False,
help="Another number.",
)
@click.option(
Expand All @@ -100,7 +99,7 @@ def worker(work: Work) -> Work:
default=False,
)
def cli(
alpha: Union[float, int], beta: Union[float, int], verbose: bool
alpha: Union[float, int], beta: Union[float, int] = 1.0, verbose: bool = False
) -> Tuple[Dict[str, float], List[str], List[str]]:
"""Click command for the math function."""
results, products, plots = math(alpha, beta)
Expand Down
15 changes: 8 additions & 7 deletions workflow/lifecycle/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import click

from workflow.definitions.work import Work
from workflow.lifecycle import configure
from workflow.utils import validate
from workflow.utils.logger import get_logger

Expand Down Expand Up @@ -35,15 +34,17 @@ def function(work: Work) -> Work:
try:
assert isinstance(work.function, str), "missing function to execute"
func: Callable[..., Any] = validate.function(work.function)
arguments: List[str] = []
# arguments: List[str] = []
parameters: Dict[str, Any] = work.parameters or {}

if isinstance(func, click.Command):
arguments = configure.arguments(func, work)
logger.info(
f"executing: {func.name}.main(args={arguments}, standalone_mode=False)"
)
outcome = func.main(args=arguments, standalone_mode=False)
# arguments = configure.arguments(func, work)
# logger.info(
# f"executing: {func.name}.main(args={arguments}, standalone_mode=False)"
# )
# outcome = func.main(args=arguments, standalone_mode=False)
# This will send the parameters as keyword arguments
outcome = func.callback(**parameters) # type: ignore
else:
logger.info(
f"executing as python function: {func.__name__}(**{work.parameters})"
Expand Down