Building newsfiles for your project.
The check command validates that appropriate news fragments exist for changes in a branch, helping enforce changelog requirements in development workflows.
The primary entry point for checking fragment requirements.
def __main(
comparewith: str | None,
directory: str | None,
config_path: str | None,
staged: bool
) -> None:
"""
Check for new fragments on a branch.
Args:
comparewith: Branch to compare against (None for auto-detection)
directory: Directory to check in (None for current directory)
config_path: Path to custom configuration file
staged: Whether to include staged files in the comparison
Exits:
0: No fragments required or fragments found
1: Fragments required but missing
"""The Click-decorated command-line interface for the check command.
def _main(
compare_with: str | None,
directory: str | None,
config: str | None,
staged: bool
) -> None:
"""
Check for new fragments on a branch.
Compares current branch against a base branch to determine if
news fragments are required for the changes made.
"""The check command automatically detects the comparison branch using this priority:
--compare-with parameterorigin/main if it existsorigin/master if it existsupstream/main if it existsupstream/master if it existsThe command analyzes changed files to determine if fragments are needed:
from towncrier.check import __main as check_main
# Check against default branch
check_main(
comparewith=None, # Auto-detect base branch
directory=None, # Current directory
config_path=None, # Auto-detect config
staged=False # Don't include staged files
)# Check against specific branch with staged files
check_main(
comparewith="develop",
directory="/path/to/project",
config_path="custom-towncrier.toml",
staged=True # Include staged changes
)# Basic check against default branch
towncrier check
# Check against specific branch
towncrier check --compare-with develop
# Include staged files in check
towncrier check --staged
# Check in specific directory
towncrier check --dir /path/to/project --config custom.toml
# Check feature branch against main
towncrier check --compare-with origin/mainFor Git repositories, the check command:
# Git-specific functions from towncrier._git
def get_remote_branches(base_directory: str) -> list[str]:
"""Get list of remote branches."""
def list_changed_files_compared_to_branch(
base_directory: str,
branch: str,
staged: bool
) -> list[str]:
"""List files changed compared to branch."""
def get_default_compare_branch(branches: Container[str]) -> str | None:
"""Get default branch for comparison."""For Mercurial repositories:
# Mercurial-specific functions from towncrier._hg
def get_remote_branches(base_directory: str) -> list[str]:
"""Get list of remote branches."""
def list_changed_files_compared_to_branch(
base_directory: str,
branch: str,
staged: bool
) -> list[str]:
"""List files changed compared to branch."""
def get_default_compare_branch(branches: Container[str]) -> str | None:
"""Get default branch for comparison."""For projects without version control:
# No-VCS fallback functions from towncrier._novcs
def get_remote_branches(base_directory: str) -> list[str]:
"""Return empty list (no branches)."""
def list_changed_files_compared_to_branch(
base_directory: str,
branch: str,
staged: bool
) -> list[str]:
"""Return empty list (no changes detectable)."""The check command identifies fragment files using:
# Pseudo-code for fragment validation
if no_files_changed:
exit(0) # No fragments required
changed_files = get_changed_files(branch, staged)
fragment_files = find_fragments(directory, config)
if has_required_changes(changed_files) and not fragment_files:
exit(1) # Fragments required but missing
else:
exit(0) # Requirements satisfiedThe check command uses these configuration values:
directory: Fragment directory locationpackage_dir: Package directory for fragment resolutionpackage: Package name for fragment locationtypes: Fragment type definitions for recognitionsections: Section configuration for multi-section projectsignore: Patterns for files that don't require fragmentsThe check command handles these scenarios:
Common usage patterns in continuous integration:
# In GitHub Actions, GitLab CI, etc.
towncrier check --compare-with ${{ github.event.pull_request.base.ref }}
# In pre-commit hooks
towncrier check --staged
# For feature branch workflows
towncrier check --compare-with origin/developInstall with Tessl CLI
npx tessl i tessl/pypi-towncrier