CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-taskipy

A task runner for Python projects that enables task definition and execution through pyproject.toml configuration.

Overview
Eval results
Files

cli.mddocs/

Command Line Interface

The primary interface for taskipy, providing both command-line execution and programmatic API access for running tasks.

Capabilities

Main Entry Point

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 Task Execution

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
    """

Usage Examples

Command Line Usage

# Run a task
task test

# Run a task with arguments
task test --verbose --failfast

# List available tasks
task --list
task -l

# Get help
task --help

Programmatic Usage

from 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}")

Integration Examples

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 0

Command Line Arguments

The CLI supports the following arguments:

  • name (positional, optional): Name of the task to run
  • args (remainder): Arguments to pass to the task
  • --list / -l: Show list of available tasks
  • --help / -h: Show help message

Exit Codes

  • 0: Success
  • 1: General error (TaskipyError)
  • 127: Task not found or invalid usage (TaskNotFoundError, InvalidUsageError)

Error Handling

The 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 1

Integration with Poetry

When using Poetry, tasks are typically run with:

poetry run task test

This ensures the task runs within the Poetry virtual environment with all dependencies available.

Standalone Usage

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 test

Install with Tessl CLI

npx tessl i tessl/pypi-taskipy

docs

cli.md

configuration.md

error-handling.md

index.md

task-composition.md

task-execution.md

variables.md

tile.json