| name | tasks-py |
| description | Create and maintain tasks.py task runner files. Use when user wants to add project automation, create a tasks.py file, add tasks, or mentions "tasks.py". |
tasks.py Task Runner
A zero-dependency Python task runner using do_ prefixed functions.
Creating a New tasks.py
Minimal (zero dependencies, self-contained): Copy tasks.py to the project root.
Maximal (argparse integration, task modules, task-by-index): Use scaffer-templates tasks.py
Use minimal for standard tasks (check, format, test). Use maximal for project-specific tasks or if you need argparse arguments.
Adding Tasks
Add new tasks by creating do_<name> functions:
def do_build(args) -> None:
"""Build the project"""
c("python -m build")
Common Task Patterns
Publishing to PyPI
def do_publish(args) -> None:
"""Publish package to PyPI"""
shutil.rmtree("dist", ignore_errors=True)
c("python -m build")
c("twine upload dist/*")
Running in subdirectory
def do_test(args) -> None:
"""Run tests in test directory"""
os.chdir("test")
c("pytest")
Using c_dir for directory-scoped commands
def do_frontend(args) -> None:
"""Build frontend"""
c_dir("npm run build", "frontend")
Task with arguments
def do_greet(args) -> None:
"""Greet someone: greet <name>"""
name = args[0] if args else "World"
print(f"Hello, {name}!")
Usage
python tasks.py
python tasks.py check
python tasks.py test -h
Library Functions Reference
| Function | Purpose |
|---|
c(cmd) | Run command, fail on error |
c_ignore(cmd) | Run command, ignore errors |
c_dir(cmd, dir) | Run command in directory |
c_spawn(cmd, cwd) | Run command in background |
copy_files(src, dest) | Copy files to destinations |
Guidelines
- Keep tasks.py at project root
- Only use standard library imports
- Document tasks with docstrings
- Use
c() for commands that must succeed
- Use
c_ignore() for optional/cleanup commands