A task runner for Python projects that enables task definition and execution through pyproject.toml configuration.
The primary interface for taskipy, providing both command-line execution and programmatic API access for running tasks.
The main CLI entry point that processes command line arguments and exits with appropriate status codes.
def main():
"""
Main CLI entry point for taskipy.
Reads sys.argv[1:] and calls run() with the arguments,
then exits with the returned status code.
"""Programmatic API for running taskipy without using the command line interface directly.
def run(args: List[str], cwd: Union[str, Path, None] = None) -> int:
"""
Run the taskipy CLI programmatically.
Args:
args: The arguments passed to the taskipy CLI
cwd: The working directory to run the task in. If not
provided, defaults to the current working directory
Returns:
0 on success; > 0 for an error
"""# Run a task
task test
# Run a task with arguments
task test --verbose --failfast
# List available tasks
task --list
task -l
# Get help
task --helpfrom taskipy.cli import run
from pathlib import Path
# Basic programmatic execution
exit_code = run(['test'])
# Run with specific working directory
exit_code = run(['test'], cwd='/path/to/project')
# Run with arguments
exit_code = run(['test', '--verbose', '--failfast'])
# List tasks programmatically
exit_code = run(['--list'])
# Handle exit codes
if exit_code == 0:
print("Task completed successfully")
elif exit_code == 127:
print("Task not found or invalid usage")
else:
print(f"Task failed with exit code {exit_code}")import subprocess
from taskipy.cli import run
# Integration with subprocess for complex workflows
def run_task_with_timeout(task_name, timeout=60):
"""Run a task with a timeout using subprocess."""
try:
result = subprocess.run(
['task', task_name],
timeout=timeout,
capture_output=True,
text=True
)
return result.returncode, result.stdout, result.stderr
except subprocess.TimeoutExpired:
return 1, "", "Task timed out"
# Integration with CI/CD systems
def ci_task_runner(tasks):
"""Run multiple tasks in CI/CD pipeline."""
for task in tasks:
print(f"Running task: {task}")
exit_code = run([task])
if exit_code != 0:
print(f"Task {task} failed with exit code {exit_code}")
return exit_code
return 0The CLI supports the following arguments:
name (positional, optional): Name of the task to runargs (remainder): Arguments to pass to the task--list / -l: Show list of available tasks--help / -h: Show help messageThe CLI handles exceptions gracefully and returns appropriate exit codes:
# TaskipyError exceptions are caught and their exit_code is returned
try:
runner = TaskRunner(cwd)
return runner.run(task_name, args)
except TaskipyError as e:
print(e)
return e.exit_code
except Exception as e:
print(e)
return 1When using Poetry, tasks are typically run with:
poetry run task testThis ensures the task runs within the Poetry virtual environment with all dependencies available.
Taskipy can also be used without Poetry in projects that have a valid pyproject.toml:
# Install globally or in virtual environment
pip install taskipy
# Run tasks directly
task testInstall with Tessl CLI
npx tessl i tessl/pypi-taskipy