CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-poetry

Python dependency management and packaging made easy.

Pending
Overview
Eval results
Files

cli-commands.mddocs/

CLI Commands

Command-line interface providing comprehensive project management through terminal commands. Includes all Poetry CLI functionality for project creation, dependency management, building, publishing, and environment management.

Capabilities

CLI Application

Main command-line application providing the poetry command and all its subcommands.

class Application:
    """
    Main CLI application for Poetry.
    
    Extends Cleo application framework to provide Poetry's
    command-line interface with plugin support and error handling.
    """
    
    def main(self) -> int:
        """
        Main entry point for CLI application.
        
        Returns:
            Exit code (0 for success, non-zero for errors)
        """
    
    def configure(self) -> None:
        """Configure application with commands and settings."""
    
    def load_plugins(self) -> None:
        """Load and register application plugins."""
    
    def handle_exception(self, exception: Exception) -> None:
        """Handle uncaught exceptions with user-friendly output."""

Base Command Class

Abstract base class for all Poetry commands providing common functionality.

class Command:
    """
    Base class for Poetry CLI commands.
    
    Provides common functionality for command implementation
    including Poetry instance access and error handling.
    """
    
    @property
    def poetry(self) -> Poetry:
        """Access to Poetry instance for current project."""
    
    def set_poetry(self, poetry: Poetry) -> None:
        """
        Set Poetry instance for command.
        
        Args:
            poetry: Poetry instance
        """
    
    def reset_poetry(self) -> None:
        """Reset Poetry instance."""
    
    def get_application(self) -> Application:
        """
        Get CLI application instance.
        
        Returns:
            Application instance
        """
    
    def handle(self) -> int:
        """
        Handle command execution (implemented by subclasses).
        
        Returns:
            Exit code (0 for success)
        """

Core Commands

Project Management Commands

Commands for creating and managing Poetry projects.

class NewCommand(Command):
    """Create new Poetry project."""
    name = "new"
    description = "Create a new Python project at <path>"
    
    def handle(self) -> int:
        """Create new project structure with pyproject.toml."""

class InitCommand(Command):
    """Initialize existing directory as Poetry project."""
    name = "init"
    description = "Initialize a pre-existing project's pyproject.toml"
    
    def handle(self) -> int:
        """Initialize pyproject.toml in current directory."""

class CheckCommand(Command):
    """Validate project configuration."""
    name = "check"
    description = "Check the validity of the pyproject.toml file"
    
    def handle(self) -> int:
        """Validate pyproject.toml and report issues."""

Dependency Management Commands

Commands for adding, removing, and updating dependencies.

class AddCommand(Command):
    """Add dependencies to project."""
    name = "add"
    description = "Add and install packages to pyproject.toml"
    
    def handle(self) -> int:
        """Add dependencies and update lock file."""

class RemoveCommand(Command):
    """Remove dependencies from project."""
    name = "remove"
    description = "Remove packages from pyproject.toml"
    
    def handle(self) -> int:
        """Remove dependencies and update lock file."""

class UpdateCommand(Command):
    """Update dependencies to latest compatible versions."""
    name = "update"
    description = "Update dependencies to latest compatible versions"
    
    def handle(self) -> int:
        """Update dependencies and lock file."""

class ShowCommand(Command):
    """Show package information."""
    name = "show"
    description = "Show information about packages"
    
    def handle(self) -> int:
        """Display package information and dependencies."""

Installation Commands

Commands for installing and synchronizing dependencies.

class InstallCommand(Command):
    """Install project dependencies."""
    name = "install"
    description = "Install project dependencies"
    
    def handle(self) -> int:
        """Install dependencies from lock file."""

class SyncCommand(Command):
    """Synchronize environment with lock file."""
    name = "sync"
    description = "Synchronize environment with lock file"
    
    def handle(self) -> int:
        """Sync environment to match lock file exactly."""

class LockCommand(Command):
    """Generate or update lock file."""
    name = "lock"
    description = "Generate or update poetry.lock file"
    
    def handle(self) -> int:
        """Generate lock file without installing."""

Build and Publishing Commands

Commands for building and publishing packages.

class BuildCommand(Command):
    """Build package distributions."""
    name = "build"
    description = "Build the source and wheels archives"
    
    def handle(self) -> int:
        """Build wheel and source distributions."""

class PublishCommand(Command):
    """Publish package to repository."""
    name = "publish"
    description = "Publish the package to a remote repository"
    
    def handle(self) -> int:
        """Publish built packages to configured repository."""

Environment Management Commands

Commands for managing virtual environments.

class EnvInfoCommand(Command):
    """Show environment information."""
    name = "env info"
    description = "Show information about the current environment"
    
    def handle(self) -> int:
        """Display environment details."""

class EnvListCommand(Command):
    """List available environments."""
    name = "env list"
    description = "List the available environments"
    
    def handle(self) -> int:
        """List virtual environments for project."""

class EnvUseCommand(Command):
    """Select Python interpreter for project."""
    name = "env use"
    description = "Set the Python interpreter to use"
    
    def handle(self) -> int:
        """Configure Python interpreter."""

class EnvRemoveCommand(Command):
    """Remove virtual environment."""
    name = "env remove"
    description = "Remove virtual environment"
    
    def handle(self) -> int:
        """Remove project virtual environment."""

class EnvActivateCommand(Command):
    """Activate virtual environment."""
    name = "env activate"
    description = "Activate the project's virtual environment"
    
    def handle(self) -> int:
        """Generate activation commands for current shell."""

Python Management Commands

Commands for managing Python interpreters with Poetry.

class PythonInstallCommand(Command):
    """Install Python interpreter."""
    name = "python install" 
    description = "Install a Python interpreter"
    
    def handle(self) -> int:
        """Install specified Python version."""

class PythonListCommand(Command):
    """List available Python interpreters."""
    name = "python list"
    description = "List available Python interpreters"
    
    def handle(self) -> int:
        """Show installed and available Python versions."""

class PythonRemoveCommand(Command):
    """Remove Python interpreter."""
    name = "python remove"
    description = "Remove an installed Python interpreter"
    
    def handle(self) -> int:
        """Remove specified Python installation."""

Configuration Commands

Commands for managing Poetry configuration.

class ConfigCommand(Command):
    """Manage Poetry configuration."""
    name = "config"
    description = "Manage configuration settings"
    
    def handle(self) -> int:
        """Get, set, or list configuration values."""

class SourceAddCommand(Command):
    """Add package source."""
    name = "source add"
    description = "Add a package source"
    
    def handle(self) -> int:
        """Add package repository source."""

class SourceRemoveCommand(Command):
    """Remove package source."""
    name = "source remove"  
    description = "Remove a package source"
    
    def handle(self) -> int:
        """Remove package repository source."""

class SourceShowCommand(Command):
    """Show package sources."""
    name = "source show"
    description = "Show information about package sources"
    
    def handle(self) -> int:
        """Display configured package sources."""

Utility Commands

Utility commands for package search, script running, and maintenance.

class SearchCommand(Command):
    """Search for packages."""
    name = "search"
    description = "Search for packages on PyPI"
    
    def handle(self) -> int:
        """Search PyPI for packages."""

class RunCommand(Command):
    """Run scripts in virtual environment."""
    name = "run"
    description = "Run a command in the appropriate environment"
    
    def handle(self) -> int:
        """Execute command in project environment."""

class VersionCommand(Command):
    """Manage project version."""
    name = "version"
    description = "Show or update the project version"
    
    def handle(self) -> int:
        """Display or update project version."""

class CacheClearCommand(Command):
    """Clear Poetry cache."""
    name = "cache clear"
    description = "Clear Poetry's cache"
    
    def handle(self) -> int:
        """Clear cached data."""

class CacheListCommand(Command):
    """List cached packages."""
    name = "cache list"
    description = "List packages stored in cache"
    
    def handle(self) -> int:
        """Display cached package information."""

Self-Management Commands

Commands for managing Poetry itself.

class SelfInstallCommand(Command):
    """Install Poetry dependencies."""
    name = "self install"
    description = "Install Poetry itself"
    
    def handle(self) -> int:
        """Install or update Poetry."""

class SelfUpdateCommand(Command):
    """Update Poetry to latest version."""
    name = "self update"
    description = "Update Poetry to the latest version"
    
    def handle(self) -> int:
        """Update Poetry installation."""

class SelfShowCommand(Command):
    """Show Poetry information."""
    name = "self show"
    description = "Show information about Poetry's installation"
    
    def handle(self) -> int:
        """Display Poetry installation details."""

Command Usage Examples

Project Creation

# Create new project
poetry new my-project

# Initialize existing directory
poetry init

# Validate project configuration
poetry check

Dependency Management

# Add dependencies
poetry add requests
poetry add pytest --group dev
poetry add "django>=3.2,<4.0"

# Remove dependencies
poetry remove requests
poetry remove pytest --group dev

# Update dependencies
poetry update
poetry update requests

# Show package information
poetry show
poetry show requests
poetry show --tree

Installation and Environment

# Install dependencies
poetry install
poetry install --no-dev
poetry install --only dev

# Synchronize environment
poetry sync

# Generate lock file
poetry lock

# Environment management
poetry env info
poetry env list
poetry env use python3.11
poetry env remove test-env

Building and Publishing

# Build distributions
poetry build
poetry build --format wheel

# Publish to PyPI
poetry publish
poetry publish --repository my-repo

Configuration

# Configuration management
poetry config --list
poetry config virtualenvs.create false
poetry config repositories.my-repo https://repo.example.com

# Package sources
poetry source add my-repo https://repo.example.com
poetry source show
poetry source remove my-repo

Utilities

# Search packages
poetry search requests

# Run commands in environment
poetry run python script.py
poetry run pytest

# Version management
poetry version
poetry version patch
poetry version 1.2.3

# Cache management
poetry cache clear pypi --all

Custom Command Development

Creating Custom Commands

from poetry.console.commands.command import Command

class MyCustomCommand(Command):
    """Custom Poetry command."""
    
    name = "my-command"
    description = "My custom functionality"
    
    def handle(self):
        """Handle command execution."""
        # Access Poetry instance
        poetry = self.poetry
        
        # Access command arguments and options
        arg = self.argument("argument_name")
        opt = self.option("option_name")
        
        # Output to user
        self.line(f"Executing custom command for {poetry.package.name}")
        
        # Custom logic here
        result = self.perform_custom_logic()
        
        if result:
            self.line("<info>Success!</info>")
            return 0
        else:
            self.line("<error>Failed!</error>")
            return 1
    
    def perform_custom_logic(self):
        """Custom command logic."""
        return True

Registering Commands via Plugin

from poetry.plugins.application_plugin import ApplicationPlugin

class MyCommandPlugin(ApplicationPlugin):
    """Plugin that adds custom commands."""
    
    @property
    def commands(self):
        """Return custom commands."""
        return [MyCustomCommand()]

Error Handling

CLI command exceptions and error conditions:

class CommandError(PoetryError):
    """Base CLI command error."""

class CommandNotFoundError(CommandError):
    """Command not found or not available."""

class ArgumentError(CommandError):
    """Invalid command arguments or options."""

class ExecutionError(CommandError):
    """Command execution failures."""

Common CLI errors:

  • Invalid command arguments or options
  • Project not found or not initialized
  • Permission errors accessing files or directories
  • Network errors during package operations
  • Environment activation or creation failures
  • Configuration validation errors

Install with Tessl CLI

npx tessl i tessl/pypi-poetry

docs

build-system.md

cli-commands.md

configuration.md

core-api.md

environment.md

index.md

installation.md

package-management.md

plugins.md

tile.json