CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-towncrier

Building newsfiles for your project.

Overview
Eval results
Files

build.mddocs/

Build Command

The build command combines individual news fragments into a comprehensive changelog entry. It supports both command-line and programmatic usage with extensive customization options.

Capabilities

Build Main Function

The primary entry point for building changelogs from news fragments.

def __main(
    draft: bool,
    directory: str | None,
    config_file: str | None,
    project_name: str | None,
    project_version: str | None,
    project_date: str | None,
    answer_yes: bool,
    answer_keep: bool
) -> None:
    """
    Build a combined news file from news fragments.
    
    Args:
        draft: If True, render to stdout without writing files or checking versions
        directory: Directory to build in (None for current directory)
        config_file: Path to custom configuration file (None for auto-detection)
        project_name: Custom project name (None to use config or auto-detect)
        project_version: Custom version string (None to use config or auto-detect) 
        project_date: Custom date string (None for current date)
        answer_yes: If True, automatically confirm fragment removal
        answer_keep: If True, keep fragments instead of removing them
    """

CLI Entry Point

The Click-decorated command-line interface for the build command.

def _main(
    draft: bool,
    directory: str | None,
    config_file: str | None,
    project_name: str | None,
    project_version: str | None,
    project_date: str | None,
    answer_yes: bool,
    answer_keep: bool
) -> None:
    """
    Build a combined news file from news fragment.
    
    This is the Click command entry point that wraps __main with error handling.
    """

Utility Functions

Helper functions for date handling and validation.

def _get_date() -> str:
    """Get current date in ISO format (YYYY-MM-DD)."""

def _validate_answer(ctx: Context, param: Option, value: bool) -> bool:
    """
    Validate that --yes and --keep options are not used together.
    
    Args:
        ctx: Click context
        param: Click option parameter
        value: Option value
        
    Returns:
        bool: The validated value
        
    Raises:
        click.Abort: If both --yes and --keep are specified
    """

def should_remove_fragment_files(
    fragment_filenames: list[str],
    answer_yes: bool,
    answer_keep: bool
) -> bool:
    """
    Determine if fragment files should be removed based on user options.
    
    Args:
        fragment_filenames: List of fragment file paths to potentially remove
        answer_yes: Whether user confirmed removal
        answer_keep: Whether user wants to keep fragments
        
    Returns:
        bool: True if fragments should be removed
    """

Usage Examples

Basic Build

from towncrier.build import __main as build_main

# Build with defaults - removes fragments after build
build_main(
    draft=False,
    directory=None,
    config_file=None,  
    project_name=None,
    project_version=None,
    project_date=None,
    answer_yes=True,
    answer_keep=False
)

Draft Build

# Generate draft output to stdout without modifying files
build_main(
    draft=True,  # Output to stdout only
    directory=None,
    config_file=None,
    project_name="My Project",
    project_version="1.2.0", 
    project_date="2024-01-15",
    answer_yes=False,  # Not relevant for draft
    answer_keep=False  # Not relevant for draft
)

Build with Custom Configuration

# Build using custom config and keeping fragments
build_main(
    draft=False,
    directory="/path/to/project",
    config_file="/path/to/custom-towncrier.toml",
    project_name="Custom Project Name",
    project_version="2.0.0-beta",
    project_date="2024-12-25",
    answer_yes=False,  # Will prompt user
    answer_keep=True   # Keep fragments after build
)

Command Line Usage

# Basic build
towncrier build

# Draft build to preview output  
towncrier build --draft

# Build with custom version and date
towncrier build --version 1.5.0 --date 2024-01-01

# Build and keep fragments
towncrier build --keep

# Build with auto-confirmation
towncrier build --yes

# Build in specific directory with custom config
towncrier build --dir /path/to/project --config custom.toml

Configuration Options

The build command uses these configuration values:

  • template: Jinja2 template for rendering the changelog
  • start_string: Marker in the news file where new content is inserted
  • filename: Name of the news/changelog file
  • package: Package name for version detection
  • package_dir: Directory containing the package
  • version: Static version string
  • name: Project name for the changelog
  • title_format: Format string for section titles
  • issue_format: Format string for issue references

Error Handling

The build command handles these error scenarios:

  • ConfigError: Invalid or missing configuration
  • UsageError: Missing required options like version
  • ClickException: General CLI errors
  • Template errors: Invalid Jinja2 templates
  • File access errors: Permission or path issues
  • VCS errors: Git/Mercurial command failures

Install with Tessl CLI

npx tessl i tessl/pypi-towncrier

docs

build.md

check.md

configuration.md

create.md

fragments.md

index.md

project.md

vcs.md

tile.json