doit/action.py
def _prepare_kwargs(task, func, args, kwargs):
        """
        Prepare keyword arguments (targets, dependencies, changed,
        cmd line options)
        Inspect python callable and add missing arguments:
        - that the callable expects
        - have not been passed (as a regular arg or as keyword arg)
        - are available internally through the task object
        """
        # Return just what was passed in task generator
        # dictionary if the task isn't available
        if not task:
            return kwargs

        func_sig = inspect.signature(func)
        sig_params = func_sig.parameters.values()
        func_has_kwargs = any(p.kind==p.VAR_KEYWORD for p in sig_params)

        # use task meta information as extra_args
        meta_args = {
            'task': lambda: task,
            'targets': lambda: list(task.targets),
            'dependencies': lambda: list(task.file_dep),
            'changed': lambda: list(task.dep_changed),
            }

        # start with dict passed together on action definition
        kwargs = kwargs.copy()
        bound_args = func_sig.bind_partial(*args)

        # add meta_args
        for key in meta_args.keys():
            # check key is a positional parameter
            if key in func_sig.parameters:
                sig_param = func_sig.parameters[key]

                # it is forbidden to use default values for this arguments
                # because the user might be unaware of this magic.
                if (sig_param.default!=sig_param.empty):
                    msg = ("Task %s, action %s(): The argument '%s' is not "
                           "allowed  to have a default value (reserved by doit)"
                           % (task.name, func.__name__, key))
                    raise InvalidTask(msg)

                # if value not taken from position parameter
                if key not in bound_args.arguments:
                    kwargs[key] = meta_args[key]()


        # add tasks parameter options
        opt_args = dict(task.options)
        if task.pos_arg is not None:
            opt_args[task.pos_arg] = task.pos_arg_val

        for key in opt_args.keys():
            # check key is a positional parameter
            if key in func_sig.parameters:
                # if value not taken from position parameter
                if key not in bound_args.arguments:
                    kwargs[key] = opt_args[key]

            # if function has **kwargs include extra_arg on it
            elif func_has_kwargs and key not in kwargs:
                kwargs[key] = opt_args[key]
        return kwargs

        Prepare keyword arguments (targets, dependencies, changed,
        cmd line options)
        Inspect python callable and add missing arguments:
        - that the callable expects
        - have not been passed (as a regular arg or as keyword arg)
        - are available internally through the task object
        
Prepare keyword arguments (targets, dependencies, changed,
cmd line options)
Inspect python callable and add missing arguments:
that the callable expects
have not been passed (as a regular arg or as keyword arg)
are available internally through the task object
Prepare keyword arguments ( targets dependencies changed cmd line options ) Inspect python callable and add missing arguments : that the callable expects have not been passed ( as a regular arg or as keyword arg ) are available internally through the task object
def _prepare_kwargs(task, func, args, kwargs):
        if not task:
            return kwargs
        func_sig = inspect.signature(func)
        sig_params = func_sig.parameters.values()
        func_has_kwargs = any(p.kind==p.VAR_KEYWORD for p in sig_params)
        meta_args = {
            'task': lambda: task,
            'targets': lambda: list(task.targets),
            'dependencies': lambda: list(task.file_dep),
            'changed': lambda: list(task.dep_changed),
            }
        kwargs = kwargs.copy()
        bound_args = func_sig.bind_partial(*args)
        for key in meta_args.keys():
            if key in func_sig.parameters:
                sig_param = func_sig.parameters[key]
                if (sig_param.default!=sig_param.empty):
                    msg = ("Task %s, action %s(): The argument '%s' is not "
                           "allowed  to have a default value (reserved by doit)"
                           % (task.name, func.__name__, key))
                    raise InvalidTask(msg)
                if key not in bound_args.arguments:
                    kwargs[key] = meta_args[key]()
        opt_args = dict(task.options)
        if task.pos_arg is not None:
            opt_args[task.pos_arg] = task.pos_arg_val
        for key in opt_args.keys():
            if key in func_sig.parameters:
                if key not in bound_args.arguments:
                    kwargs[key] = opt_args[key]
            elif func_has_kwargs and key not in kwargs:
                kwargs[key] = opt_args[key]
        return kwargs
def _prepare_kwargs ( task , func , args , kwargs ) : if not task : return kwargs func_sig = inspect . signature ( func ) sig_params = func_sig . parameters . values ( ) func_has_kwargs = any ( p . kind == p . VAR_KEYWORD for p in sig_params ) meta_args = { 'task' : lambda : task , 'targets' : lambda : list ( task . targets ) , 'dependencies' : lambda : list ( task . file_dep ) , 'changed' : lambda : list ( task . dep_changed ) , } kwargs = kwargs . copy ( ) bound_args = func_sig . bind_partial ( * args ) for key in meta_args . keys ( ) : if key in func_sig . parameters : sig_param = func_sig . parameters [ key ] if ( sig_param . default != sig_param . empty ) : msg = ( "Task %s, action %s(): The argument '%s' is not " "allowed  to have a default value (reserved by doit)" % ( task . name , func . __name__ , key ) ) raise InvalidTask ( msg ) if key not in bound_args . arguments : kwargs [ key ] = meta_args [ key ] ( ) opt_args = dict ( task . options ) if task . pos_arg is not None : opt_args [ task . pos_arg ] = task . pos_arg_val for key in opt_args . keys ( ) : if key in func_sig . parameters : if key not in bound_args . arguments : kwargs [ key ] = opt_args [ key ] elif func_has_kwargs and key not in kwargs : kwargs [ key ] = opt_args [ key ] return kwargs
Prepare keyword arguments (targets, dependencies, changed,
cmd line options)
Inspect python callable and add missing arguments:
 that the callable expects
 have not been passed (as a regular arg or as keyword arg)
 are available internally through the task object
Prepare keyword arguments ( targets dependencies changed cmd line options ) Inspect python callable and add missing arguments : that the callable expects have not been passed ( as a regular arg or as keyword arg ) are available internally through the task object
"""
        Prepare keyword arguments (targets, dependencies, changed,
        cmd line options)
        Inspect python callable and add missing arguments:
        - that the callable expects
        - have not been passed (as a regular arg or as keyword arg)
        - are available internally through the task object
        """ # Return just what was passed in task generator # dictionary if the task isn't available # use task meta information as extra_args # start with dict passed together on action definition # add meta_args # check key is a positional parameter # it is forbidden to use default values for this arguments # because the user might be unaware of this magic. # if value not taken from position parameter # add tasks parameter options # check key is a positional parameter # if value not taken from position parameter # if function has **kwargs include extra_arg on it
task
func
args
kwargs