Xaras
Xaras

Reputation: 1

doit is running every function inside dodo.py. Can I change that?

I am trying to automate a flow and I encountered a problem with "doit", because it is running all the functions inside dodo.py and I do not want it to do that.

I'm working on Python 2.7 using "doit" feature. Below is a part of the code from the dodo.py file. The problem is that when I try to run "doit list" ( a basic function from doit ) it also prints those 2 messages from my functions.

I've tried to set the DOIT_CONFIG, I've tried to use "uptodate: [True]", but none of that worked.

I read around web that python is executing commands in 2 steps. In the first step it is running all the functions and after that it is running the command that you wrote.

What I want to ask is that is there a way to disable this "feature" ? All I want is to run "doit list" without calling task "setup" and "test", because task "test" is printing text and is waiting for an input, even if "doit list" doesn't need them.

Is there a way to tell "doit" not to execute some function unless I call them ? Since there are no dependencies, I think there should be a way, but I couldn't find it.


def task_setup():
    print("Doing setup")
    a = 3

    return a

def task_test():

    items = os.listdir(pd_audit_path)
    fileList = []

    for names in items:
        if names.startswith(pd_step):
            fileList.append(names)
    cnt = 0                                                       
    for fileName in fileList:
        sys.stdout.write( "[%d] %s\n\r" %(cnt, fileName) )
        cnt = cnt + 1                              

    fileName = int(input("\n\rSelect run [0 - " + str(cnt - 1) + "]: "))
    path = fileList[fileName]

    return { 
        'file_dep': [],                          
        'actions': ['The path is: %s',%(path)],
        'params':[{'name':'all', 'long': 'all', 'type': bool,
        'default': True, 'help': 'all relevant reports'},],
        'verbosity': 2,
    } 

When I call "doit list" I am expecting a list with all the tasks from dodo.py, but it also prints the messages from task "setup" and "test".

Upvotes: 0

Views: 607

Answers (1)

saimn
saimn

Reputation: 443

From the docs:

A function that starts with the name task_ defines a task-creator recognized by doit. These functions must return (or yield) dictionaries representing a task.

doit needs to execute these functions in order to get the task definitions, and to know which tasks must be executed. So you should name your utility functions with starting with task_, and not print inside the task functions unless it is necessary, e.g. for debugging.

Upvotes: 1

Related Questions