Skip to content

Commit

Permalink
Fix handling of switch tasks and task with uses option in dry-run mode
Browse files Browse the repository at this point in the history
…#115

Since it's not possible to properly resolve the content of these tasks
without actually executing the tasks they depend on, instead of
outputting the task content we print a message that it is unresolved.
  • Loading branch information
nat-n committed Jan 15, 2023
1 parent be6a5f6 commit e056c26
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
15 changes: 13 additions & 2 deletions poethepoet/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ def run(
Run this task
"""
upstream_invocations = self._get_upstream_invocations(context)

if context.dry and upstream_invocations.get("uses", {}):
self._print_action(
f"unresolved dependency task results via uses option for task {self.name!r}",
dry=True,
unresolved=True,
)
return 0

return self._handle_run(
context,
extra_args,
Expand Down Expand Up @@ -484,12 +493,14 @@ def _validate_task_def(
issue = None
return issue

def _print_action(self, action: str, dry: bool):
def _print_action(self, action: str, dry: bool, unresolved: bool = False):
"""
Print the action taken by a task just before executing it.
"""
min_verbosity = -1 if dry else 0
arrow = "<=" if self.options.get("capture_stdout") else "=>"
arrow = (
"??" if unresolved else "<=" if self.options.get("capture_stdout") else "=>"
)
self._ui.print_msg(
f"<hl>Poe {arrow}</hl> <action>{action}</action>", min_verbosity
)
Expand Down
6 changes: 6 additions & 0 deletions poethepoet/task/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def _handle_run(
f"Switch task {self.name!r} aborted after failed control task"
)

if context.dry:
self._print_action(
f"unresolved case for switch task", dry=True, unresolved=True
)
return 0

control_task_output = context.get_task_output(self.control_task.invocation)
case_task = self.switch_tasks.get(
control_task_output, self.switch_tasks.get(DEFAULT_CASE)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_graph_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ def test_call_attr_func(run_poe_subproc):
"here we go...\n" "Thinking about and\n" "hello and hello\n"
)
assert result.stderr == ""


def test_uses_dry_run(run_poe_subproc):
result = run_poe_subproc("-d", "deep-graph-with-args", project="graphs")
assert result.capture == (
"Poe => poe_test_echo here we go...\n"
"Poe => :\n"
"Poe <= poe_test_echo about\n"
"Poe <= poe_test_echo hello\n"
"Poe ?? unresolved dependency task results via uses option for task 'think'\n"
"Poe ?? unresolved dependency task results via uses option for task 'deep-graph-with-args'\n"
)
assert result.stdout == ""
assert result.stderr == ""
9 changes: 9 additions & 0 deletions tests/test_switch_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def test_switch_default_fail(run_poe_subproc):
assert result.stderr == ""


def test_switch_dry_run(run_poe_subproc):
result = run_poe_subproc("-d", "var_dependent", project="switch")
assert result.capture == (
"Poe <= int(${FOO_VAR}) % 2\n" "Poe ?? unresolved case for switch task\n"
)
assert result.stdout == ""
assert result.stderr == ""


def test_switch_multivalue_case(run_poe_subproc):
for num in ("1", "3", "5"):
result = run_poe_subproc(
Expand Down

0 comments on commit e056c26

Please sign in to comment.