System Handlers¶
The system handlers module (cli_system.py) contains handlers for system-level commands that operate on packages outside of environments.
Overview¶
This module provides handlers for:
- Package Creation: Generate package templates from scratch
- Package Validation: Validate packages against the Hatch schema
Handler Functions¶
Package Creation¶
handle_create(): Create a new package template with standard structure
Features: - Generates complete package template - Creates pyproject.toml with Hatch metadata - Sets up source directory structure - Includes README and LICENSE files - Provides basic MCP server implementation
Package Validation¶
handle_validate(): Validate a package against the Hatch schema
Validation Checks: - pyproject.toml structure and required fields - Hatch-specific metadata (mcp_server entry points) - Package dependencies and version constraints - Package structure compliance
Handler Signature¶
All handlers follow the standard signature:
def handle_system_command(args: Namespace) -> int:
"""Handle 'hatch command' command.
Args:
args: Namespace with:
- env_manager: HatchEnvironmentManager instance
- <command-specific arguments>
Returns:
Exit code (0 for success, 1 for error)
"""
Module Reference¶
hatch.cli.cli_system
¶
System CLI handlers for Hatch.
This module contains handlers for system-level commands that operate on packages as a whole rather than within environments.
Commands
- hatch create
: Create a new package template from scratch - hatch validate
: Validate a package against the Hatch schema
Package Creation
The create command generates a complete package template with: - pyproject.toml with Hatch metadata - Source directory structure - README and LICENSE files - Basic MCP server implementation
Package Validation
The validate command checks: - pyproject.toml structure and required fields - Hatch-specific metadata (mcp_server entry points) - Package dependencies and version constraints
Handler Signature
All handlers follow: (args: Namespace) -> int Returns: EXIT_SUCCESS (0) on success, EXIT_ERROR (1) on failure
Example
$ hatch create my-mcp-server --description "My custom MCP server" $ hatch validate ./my-mcp-server
Classes¶
Functions¶
handle_create(args)
¶
Handle 'hatch create' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - name: Package name - dir: Target directory (default: current directory) - description: Package description (optional) |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 for error) |
Source code in hatch/cli/cli_system.py
handle_validate(args)
¶
Handle 'hatch validate' command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace
|
Namespace with: - env_manager: HatchEnvironmentManager instance - package_dir: Path to package directory |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code (0 for success, 1 for error) |