CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-hatchling

Modern, extensible Python build backend implementing PEP 517/660 standards with plugin architecture.

Pending
Overview
Eval results
Files

build-backend.mddocs/

PEP 517/660 Build Backend

Core build backend functions implementing Python packaging standards (PEP 517 and PEP 660) for integration with build frontends like pip, build, and other packaging tools.

Capabilities

Source Distribution Building

Creates source distributions (sdist) containing all source files needed to build the project.

def build_sdist(sdist_directory: str, config_settings: dict[str, Any] | None = None) -> str:
    """
    Build a source distribution.
    
    Args:
        sdist_directory: Directory where the sdist will be written
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        str: Basename of the built sdist file
        
    PEP Reference:
        https://peps.python.org/pep-0517/#build-sdist
    """

Wheel Building

Creates wheel distributions (.whl files) containing compiled bytecode and data files for installation.

def build_wheel(
    wheel_directory: str,
    config_settings: dict[str, Any] | None = None,
    metadata_directory: str | None = None
) -> str:
    """
    Build a wheel distribution.
    
    Args:
        wheel_directory: Directory where the wheel will be written
        config_settings: Optional configuration settings from build frontend
        metadata_directory: Optional directory containing prepared metadata
        
    Returns:
        str: Basename of the built wheel file
        
    PEP Reference:
        https://peps.python.org/pep-0517/#build-wheel
    """

Editable Wheel Building

Creates editable wheels for development installations that link to source code rather than copying files.

def build_editable(
    wheel_directory: str,
    config_settings: dict[str, Any] | None = None,
    metadata_directory: str | None = None
) -> str:
    """
    Build an editable wheel distribution.
    
    Args:
        wheel_directory: Directory where the editable wheel will be written
        config_settings: Optional configuration settings from build frontend
        metadata_directory: Optional directory containing prepared metadata
        
    Returns:
        str: Basename of the built editable wheel file
        
    PEP Reference:
        https://peps.python.org/pep-0660/#build-editable
    """

Build Dependencies

Functions to determine build-time dependencies before building distributions.

def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]:
    """
    Get build dependencies for source distribution.
    
    Args:
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        list[str]: List of build dependency specifications
        
    PEP Reference:
        https://peps.python.org/pep-0517/#get-requires-for-build-sdist
    """

def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]:
    """
    Get build dependencies for wheel distribution.
    
    Args:
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        list[str]: List of build dependency specifications
        
    PEP Reference:
        https://peps.python.org/pep-0517/#get-requires-for-build-wheel
    """

def get_requires_for_build_editable(config_settings: dict[str, Any] | None = None) -> list[str]:
    """
    Get build dependencies for editable wheel distribution.
    
    Args:
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        list[str]: List of build dependency specifications (includes editables requirement)
        
    PEP Reference:
        https://peps.python.org/pep-0660/#get-requires-for-build-editable
    """

Metadata Preparation (Optional)

These functions are only available when not running under pip to avoid dependency resolution issues.

def prepare_metadata_for_build_wheel(
    metadata_directory: str,
    config_settings: dict[str, Any] | None = None
) -> str:
    """
    Prepare wheel metadata without building the full wheel.
    
    Args:
        metadata_directory: Directory where metadata will be written
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        str: Basename of the metadata directory
        
    PEP Reference:
        https://peps.python.org/pep-0517/#prepare-metadata-for-build-wheel
        
    Note:
        Only available when PIP_BUILD_TRACKER environment variable is not set
    """

def prepare_metadata_for_build_editable(
    metadata_directory: str,
    config_settings: dict[str, Any] | None = None
) -> str:
    """
    Prepare editable wheel metadata without building the full wheel.
    
    Args:
        metadata_directory: Directory where metadata will be written
        config_settings: Optional configuration settings from build frontend
        
    Returns:
        str: Basename of the metadata directory
        
    PEP Reference:
        https://peps.python.org/pep-0660/#prepare-metadata-for-build-editable
        
    Note:
        Only available when PIP_BUILD_TRACKER environment variable is not set
    """

Usage Examples

Basic Build Backend Configuration

# pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

Programmatic Usage

import os
from hatchling.build import build_wheel, build_sdist, get_requires_for_build_wheel

# Get build dependencies
deps = get_requires_for_build_wheel()
print(f"Build dependencies: {deps}")

# Build a wheel
wheel_name = build_wheel("dist")
print(f"Built wheel: {wheel_name}")

# Build a source distribution
sdist_name = build_sdist("dist")
print(f"Built sdist: {sdist_name}")

With Configuration Settings

# Configuration settings can be passed by build frontends
config_settings = {
    "build-dir": "custom_build",
    "skip-binary-deps": "true"
}

wheel_name = build_wheel("dist", config_settings=config_settings)

Error Handling

Build backend functions may raise various exceptions:

  • ValueError: Invalid configuration or settings
  • FileNotFoundError: Missing required files or directories
  • PermissionError: Insufficient permissions for file operations
  • RuntimeError: Build failures or internal errors

Build frontends should handle these exceptions appropriately and provide meaningful error messages to users.

Integration Notes

Build Frontend Integration

Hatchling integrates with build frontends through the standardized PEP 517/660 interface:

  1. Frontend calls get_requires_for_build_* to determine dependencies
  2. Frontend installs dependencies in build environment
  3. Frontend calls build_* functions to create distributions
  4. Optional: Frontend may call prepare_metadata_for_build_* for metadata-only operations

Bootstrap Building

Hatchling includes a special ouroboros.py module for self-building that provides the same PEP 517/660 interface but with minimal dependencies for bootstrapping the build process.

Install with Tessl CLI

npx tessl i tessl/pypi-hatchling

docs

build-backend.md

builders.md

cli.md

index.md

metadata.md

plugins.md

version.md

tile.json