Automation tool that brings the power of build-tools to execute any kind of task with efficient DAG-based execution and plugin architecture
—
Complete command-line interface with extensible commands, configuration management, plugin system, and comprehensive CLI application framework.
Core CLI application class that handles command parsing, configuration loading, and command execution.
class DoitMain:
"""
Main CLI application class for doit command-line interface.
Handles command parsing, configuration loading, plugin management,
and execution of doit commands with proper error handling.
"""
BIN_NAME = sys.argv[0].split('/')[-1] # Binary name for help/error messages
DOIT_CMDS = (Help, Run, List, Info, Clean, Forget, Ignore, DumpDB, Strace, TabCompletion, ResetDep)
def __init__(self, task_loader=None, config_filenames=('pyproject.toml', 'doit.cfg'), extra_config=None):
"""
Initialize DoitMain instance.
Args:
task_loader: Task loader instance for discovering tasks
config_filenames (str|list): Configuration file names to load
extra_config (dict, optional): Extra configuration values by section
"""
def run(self, all_args):
"""
Entry point for all commands.
Args:
all_args (list): Command line arguments
Returns:
int: Exit code (0=success, 1=task failure, 2=task error, 3=user error)
"""
def get_cmds(self):
"""
Get all available sub-commands including plugins.
Returns:
PluginDict: Dictionary of command name to command class
"""
@staticmethod
def print_version():
"""Print doit version and library location"""
def process_args(self, cmd_args):
"""
Process command line arguments, extract global variables.
Args:
cmd_args (list): Raw command line arguments
Returns:
list: Arguments with global variables removed
"""Classes for loading and managing configuration from TOML and INI files.
class DoitConfig:
"""
Parse and store values from INI and TOML configuration files.
Supports both traditional INI format and modern TOML format with
proper section handling and plugin configuration.
"""
PLUGIN_TYPES = ['command', 'loader', 'backend', 'reporter']
def __init__(self):
"""Initialize configuration parser"""
def loads(self, config_filenames):
"""
Load configuration from multiple files.
Args:
config_filenames (list): List of configuration file paths
"""
@property
def toml(self):
"""Get available TOML library (tomllib, tomli, or tomlkit)"""
def as_dict(self):
"""Return configuration values in dictionary format"""
@staticmethod
def load_config_ini(filenames):
"""
Read configuration from INI files.
Args:
filenames (str|list): INI file path(s) to read
Returns:
ConfigParser: Parsed INI configuration
"""
def load_config_toml(self, filename, prefix):
"""
Read configuration from TOML file.
Args:
filename (str): TOML file path
prefix (str): Section prefix (e.g., 'tool.doit')
Returns:
dict: Parsed TOML configuration
"""Functions for managing command-line variables that can be accessed within tasks.
def get_var(name, default=None):
"""
Get value of command-line variable.
Args:
name (str): Variable name
default: Default value if variable not set
Returns:
Variable value or default, None if variables not initialized
"""
def set_var(name, value):
"""
Set command-line variable value.
Args:
name (str): Variable name
value: Variable value
"""
def reset_vars():
"""Reset all command-line variables to empty state"""Built-in commands available through the CLI interface.
# Core Commands (all extend base command class)
class Help: """Display help information"""
class Run: """Execute tasks (default command)"""
class List: """List available tasks"""
class Info: """Show task information and metadata"""
class Clean: """Clean task outputs and targets"""
class Forget: """Forget task execution state"""
class Ignore: """Ignore task failures"""
class DumpDB: """Dump dependency database contents"""
class Strace: """Trace task file dependencies"""
class TabCompletion: """Generate shell tab completion"""
class ResetDep: """Reset task dependencies"""# List all available tasks
doit list
# Run all tasks (default command)
doit
# Run specific tasks
doit build test
# Get help for specific command
doit help run
# Show task information
doit info build
# Clean task outputs
doit clean
# Run with variables
doit build version=1.2.0 env=production
# Run with specific verbosity
doit -v 2 build
# Continue on errors
doit --continue build test deployfrom doit.doit_cmd import DoitMain
from doit.cmd_base import ModuleTaskLoader
def task_custom():
"""Custom task"""
return {'actions': ['echo "Custom application"']}
def main():
"""Custom CLI application using doit framework"""
# Create task loader with current module
loader = ModuleTaskLoader(globals())
# Create main application instance
app = DoitMain(
task_loader=loader,
config_filenames=['myapp.cfg', 'pyproject.toml']
)
# Override binary name for help messages
app.BIN_NAME = 'myapp'
# Run with command line arguments
import sys
result = app.run(sys.argv[1:])
sys.exit(result)
if __name__ == '__main__':
main()TOML Configuration (pyproject.toml):
[tool.doit]
default_tasks = ["build", "test"]
continue = true
verbosity = 2
[tool.doit.commands.run]
parallel_type = "process"
num_process = 4
[tool.doit.tasks.build]
verbosity = 1
[tool.doit.plugins.command]
my_command = "mypackage.commands:MyCommand"INI Configuration (doit.cfg):
[GLOBAL]
default_tasks = build,test
continue = True
verbosity = 2
[run]
parallel_type = process
num_process = 4
[task:build]
verbosity = 1
[COMMAND]
my_command = mypackage.commands:MyCommandfrom doit import get_var
def task_deploy():
"""Deploy to specified environment"""
env = get_var('env', 'development')
version = get_var('version', '1.0.0')
return {
'actions': [f'deploy.sh --env {env} --version {version}'],
'verbosity': 2
}
# Run with: doit deploy env=production version=2.1.0from doit.cmd_base import Command
class MyCustomCommand(Command):
"""Custom command plugin"""
name = 'mycmd'
@staticmethod
def add_cmd_options(parser):
"""Add command-specific options"""
parser.add_option('--option', help='Custom option')
def execute(self, opt_values, pos_args):
"""Execute custom command"""
print(f"Running custom command with option: {opt_values['option']}")
return 0 # Success
# Register in configuration:
# [COMMAND]
# mycmd = mypackage.commands:MyCustomCommandInstall with Tessl CLI
npx tessl i tessl/pypi-doit