Skip to content

Ability to print action before executing it. #390

Open

Description

@Jasha10

Feature request: ability to print some data about each action before it gets executed.

Motivation:

If my task has multiple actions (and verbosity==2), I can't tell which output came from which action (assuming that the actions all succeed). Some way to tell which output comes from which action would be great. Printing e.g. the shell command that will be run, before running it, would be a good way to achieve this.

If you write echo 123 as part of a recipe in a Makefile (using GNU make), the following is printed:

+ echo 123
123

This is great for debugging purposes, so that you will know what command has produced the output you are seeing. The + symbol prefix makes it easy to tell what is the command, and what is the output from the command.

Possible API design:

Perhaps this could be verbosity level 3?

For CmdAction, it should be easy to print the action that will be executed by Popen, just before it gets executed.

For PythonAction, it is not as clear what should be the output. Perhaps a str representation of the python-action and it's args and kwargs...

Describe alternatives you've considered

I have tried using the title keyword for the task, with a custom title printer:

# dodo.py
import doit

def show_cmd(task):
    result = "EXECUTING " + task.name
    for action in task.actions:
        if isinstance(action, doit.action.CmdAction):
            result += "\n+ " + action.expand_action()
        if isinstance(action, doit.action.PythonAction):
            result += f"\n+ {action.py_callable.__name__}(*{action.args}, **{action._prepare_kwargs()})"
    return result

def py_action(a=1, b=3):
    print(f"in py_action: {a=}, {b=}")

def task_custom_display():
    return {"actions": ["echo abc efg", (py_action, (2,), {"b": 4})], "title": show_cmd}

However, when I run doit --verbosity 2 on this dodo.py file, the results are out of order:

$ doit --verbosity 2
.  EXECUTING custom_display
+ echo abc efg
+ py_action(*(2,), **{'b': 4})
abc efg
in py_action: a=2, b=4

I still cannot tell where the stdout from the first action ("abc efg") end, and the stdout from the second action ("in py_action: a=2, b=4") begins. This is why I'm requesting this feature.

Activity

  1. schettino72 commented on Apr 10, 2021

    @schettino72
    Member

    If it is just for debugging you can easily:

    'actions' : ['echo Executing cmd X', 'X',
                     'echo Executing function foo(), 'foo()']
    

    title is for a task, so it wont work for your use-case.

    I dont think messing with verbosity it would be a good idea, adding a new parameter would be ok.

    For PythonAction, it is not as clear what should be the output. Perhaps a str representation of the python-action and it's args and kwargs...

    I guess this would be a good default, but it should be possible to overwrite it (implemented as class method).

    TODO:

    • add new command line option --show-action (better name suggestions welcome)
    • implement a title() method for PythonAction & CmdAction
    • Reporter will also need a new method to be called before each action
  2. maximlt commented on Jan 27, 2022

    @maximlt

    This would be very useful for debugging tasks that you've not created yourself but inherited from another package.

  3. schettino72 commented on Jan 27, 2022

    @schettino72
    Member

    @maximlt there is PR open for that.

    I cant remember which state was it... does that work for you?
    Did it implement my spec above?
    Maybe you can help review it...

  4. maximlt commented on Jan 28, 2022

    @maximlt

    Sorry @schettino72 I've got really low bandwidth these days, hopefully some time later! Thanks for your prompt answer anyway.

  5. awesomescot commented on Dec 27, 2023

    @awesomescot

    I would find this useful also. 👍

  6. Jasha10 commented on Dec 28, 2023

    @Jasha10
    ContributorAuthor

    Feel free to pick up the partial PR #392. Sorry to say I won't be able to finish the PR myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions