A lightweight Python task runner with dependency resolution, execution tracking, and CLI support.
- Dependency Resolution - Topological sort with cycle detection
- Decorator API - Register tasks with
@runner.task(deps=[...]) - Dry Run - Preview execution order without running
- Execution Tracking - Duration, success/failure, output capture
- Statistics - Track runs, successes, and failures
- CLI Interface - Run tasks from the command line
from pytaskrunner import TaskRunner
runner = TaskRunner()
@runner.task()
def clean():
"""Remove build artifacts."""
import shutil
shutil.rmtree("build", ignore_errors=True)
return "cleaned"
@runner.task(deps=["clean"])
def build():
"""Compile the project."""
return "built"
@runner.task(deps=["build"])
def test():
"""Run the test suite."""
return "tested"
# Run with dependencies resolved automatically
results = runner.run("test")
# Executes: clean -> build -> test# Run a task
pytaskrunner -f tasks.py build
# List all tasks
pytaskrunner -f tasks.py --list
# Dry run
pytaskrunner -f tasks.py --dry-run testfrom pytaskrunner import TaskRunner, TaskError
runner = TaskRunner()
try:
runner.run("build")
except TaskError as e:
print(f"Task '{e.task_name}' failed: {e.reason}")
print(f"Duration before failure: {e.duration:.3f}s")pytest