nat-n / poethepoet

A task runner that works well with poetry.
https://poethepoet.natn.io/
MIT License
1.39k stars 56 forks source link

Can't run task that `uses` a `switch` task #182

Closed emanueljg closed 9 months ago

emanueljg commented 9 months ago

I'm trying to run poetry run poe user from the following configuration:

[tool.poe.tasks.switcher]
control.expr = "sys.platform"

  [[tool.poe.tasks.switcher.switch]]
  case = "win32"
  cmd = "echo win32"

  [[tool.poe.tasks.switcher.switch]]
  cmd = "echo other"

[tool.poe.tasks.user]
uses = { switched = "switcher" }
cmd = "echo $switched"

I get this error:

Traceback (most recent call last):
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/bin/poe", line 8, in <module>
    sys.exit(main())
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/__init__.py", line 35, in main
    result = app(cli_args=sys.argv[1:])
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/app.py", line 121, in __call__
    return self.run_task_graph(task) or 0
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/app.py", line 175, in run_task_graph
    return self.run_task(stage_task, context)
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/app.py", line 156, in run_task
    return task.run(context=context, extra_args=task.invocation[1:])
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/task/base.py", line 271, in run
    context.get_task_env(
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/context.py", line 63, in get_task_env
    result.update(self._get_dep_values(task_uses))
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/context.py", line 73, in _get_dep_values
    return {
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/context.py", line 74, in <dictcomp>
    var_name: self.get_task_output(invocation)
  File "/home/ejg/.cache/pypoetry/virtualenvs/wtf-lV5BMhTQ-py3.10/lib/python3.10/site-packages/poethepoet/context.py", line 99, in get_task_output
    return re.sub(r"\s+", " ", self.captured_stdout[invocation].strip("\r\n"))
KeyError: ('switcher',)

switcher works fine to run on its own. If I comment out uses (or try to use a normal cmd task, for example), user works just fine. But the two won't work together.

nat-n commented 9 months ago

Hi @emanueljg, thanks for reporting this. I see what's going wrong here is that the output from the switch task doesn't get captured, because the switch task itself doesn't have any output (only the subtasks do). But I agree that one would expect this to work. I'll try get a fix out for it soon :)

nat-n commented 9 months ago

This is now fixed in 0.24.4 🚀