CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-doit

Automation tool that brings the power of build-tools to execute any kind of task with efficient DAG-based execution and plugin architecture

Pending
Overview
Eval results
Files

task-definition.mddocs/

Task Definition and Loading

Functions and decorators for defining tasks, managing delayed task creation, parameterizing task generators, and loading task definitions from modules.

Capabilities

Task Creator Decorators

Decorators for enhancing task creator functions with parameter definitions and delayed execution capabilities.

def create_after(executed=None, target_regex=None, creates=None):
    """
    Decorator to annotate a task-creator function with delayed loader info.
    
    Allows tasks to be created after other tasks have been executed, enabling
    dynamic task creation based on execution results.
    
    Args:
        executed (str, optional): Name of task that should be executed before
                                calling the creator function
        target_regex (str, optional): Regex for all targets this loader will create
        creates (list, optional): List of explicit task basenames this creator will generate
        
    Returns:
        function: Decorated task creator function
    """
def task_params(param_def):
    """
    Decorator to annotate a task-creator function with parameter definitions.
    
    Enables task creators to accept command line arguments and configuration
    parameters with proper parsing and validation.
    
    Args:
        param_def (list): List of parameter definition dictionaries with keys:
                         - name: parameter name
                         - type: parameter type (str, int, bool, etc.)
                         - default: default value
                         - help: help text
    
    Returns:
        function: Decorated task creator function
        
    Raises:
        ValueError: If param_def is not a valid parameter definition list
    """

Task Loading and Generation

Functions for discovering task creators, loading tasks from namespaces, and generating task objects.

def load_tasks(namespace, command_names=(), allow_delayed=False, args=(), config=None, task_opts=None):
    """
    Find task-creators and create tasks from a namespace dictionary.
    
    Discovers functions with names starting with 'task_' or objects with
    'create_doit_tasks' method and converts them to Task objects.
    
    Args:
        namespace (dict): Dictionary containing task creators and other objects
        command_names (tuple): Blacklist of command names that can't be task names
        allow_delayed (bool): Whether to ignore delayed task execution dependencies
        args (list): Command line arguments for task parameter parsing
        config (dict): Configuration from TOML/INI files
        task_opts (dict): Task options passed through API
        
    Returns:
        list: List of Task objects in definition order
        
    Raises:
        InvalidTask: If task definition is invalid
        InvalidDodoFile: If task names conflict with command names
    """
def generate_tasks(func_name, gen_result, gen_doc=None):
    """
    Create tasks from a task generator result.
    
    Processes the return value from a task creator function and converts
    it into Task objects, handling dictionaries, generators, and Task instances.
    
    Args:
        func_name (str): Name of the task generator function
        gen_result: Value returned by task generator (dict, generator, or Task)
        gen_doc (str, optional): Docstring from task generator function
        
    Returns:
        tuple: Tuple of Task objects
        
    Raises:
        InvalidTask: If generator result is invalid format
    """

Module and Configuration Loading

Functions for loading dodo modules and configuration from Python files and TOML/INI files.

def get_module(dodo_file, cwd=None, seek_parent=False):
    """
    Find and import Python module defining tasks (dodo file).
    
    Locates and imports the dodo file, setting up the proper Python path
    and working directory for task execution.
    
    Args:
        dodo_file (str): Path to file containing task definitions
        cwd (str, optional): Working directory to use, defaults to dodo file directory
        seek_parent (bool): Search for dodo file in parent directories if not found
        
    Returns:
        module: Imported Python module containing task definitions
        
    Raises:
        InvalidDodoFile: If dodo file cannot be found or imported
        InvalidCommand: If specified cwd is not a directory
    """
def load_doit_config(dodo_module):
    """
    Load DOIT_CONFIG dictionary from dodo module.
    
    Extracts configuration settings from the DOIT_CONFIG variable in
    the dodo module, providing default configuration options.
    
    Args:
        dodo_module (dict): Dictionary with module members
        
    Returns:
        dict: Configuration dictionary
        
    Raises:
        InvalidDodoFile: If DOIT_CONFIG is not a dictionary
    """

Constants and Variables

TASK_STRING = "task_"  # Prefix used to identify task generator functions

initial_workdir = None  # Directory path from where doit was executed (set by loader)

Usage Examples

Basic Task Creator with Parameters

from doit import task_params

@task_params([
    {'name': 'env', 'type': str, 'default': 'dev', 'help': 'Environment to deploy to'},
    {'name': 'verbose', 'type': bool, 'default': False, 'help': 'Enable verbose output'}
])
def task_deploy(env, verbose):
    """Deploy application to specified environment"""
    cmd = f'deploy.sh --env {env}'
    if verbose:
        cmd += ' --verbose'
    
    return {
        'actions': [cmd],
        'verbosity': 2 if verbose else 1
    }

# Run with: doit deploy --env production --verbose

Delayed Task Creation

from doit import create_after

@create_after(executed='setup')
def task_dynamic_tests():
    """Create test tasks based on setup results"""
    # This will only run after 'setup' task completes
    test_files = discover_test_files_from_setup()
    
    for test_file in test_files:
        yield {
            'name': f'test_{test_file}',
            'actions': [f'python -m pytest {test_file}'],
            'file_dep': [test_file]
        }

Task Generator with Subtasks

def task_process_files():
    """Process all data files"""
    for filename in glob.glob('data/*.txt'):
        yield {
            'name': filename,
            'file_dep': [filename],
            'targets': [filename.replace('.txt', '.processed')],
            'actions': [f'process_data.py {filename}']
        }

Configuration Loading

# In dodo.py
DOIT_CONFIG = {
    'default_tasks': ['build', 'test'],
    'continue': True,
    'verbosity': 2,
}

def task_build():
    return {'actions': ['python setup.py build']}

Install with Tessl CLI

npx tessl i tessl/pypi-doit

docs

actions.md

cli.md

core-api.md

exceptions.md

index.md

task-definition.md

tools.md

tile.json