Building newsfiles for your project.
npx @tessl/cli install tessl/pypi-towncrier@25.8.0Towncrier is a utility to produce useful, summarized news files (changelogs) for your project. Rather than reading Git history or having one single file which developers all write to and produce merge conflicts, towncrier reads "news fragments" which contain information useful to end users.
pip install towncrierimport towncrierFor programmatic usage:
from towncrier.build import __main as build_main
from towncrier.create import __main as create_main
from towncrier.check import __main as check_main
from towncrier._settings import load_config_from_options, Config
from towncrier._builder import find_fragments, render_fragments, parse_newfragment_basename
from towncrier._project import get_version, get_project_name
from towncrier._writer import append_to_newsfile
from towncrier._vcs import remove_files, stage_newsfile, get_remote_branchesBuild a changelog from news fragments:
towncrier buildCreate a new news fragment:
towncrier create 123.featureCheck for news fragments on a branch:
towncrier check --compare-with origin/mainfrom towncrier.build import __main as build_main
from towncrier._settings import load_config_from_options
# Load configuration
base_directory, config = load_config_from_options(
directory=None, # Use current directory
config_path=None # Auto-detect config file
)
# Build changelog programmatically
build_main(
draft=False, # Write to files
directory=None, # Use current directory
config_file=None, # Use auto-detected config
project_name=None, # Use config or auto-detect
project_version=None, # Use config or auto-detect
project_date=None, # Use current date
answer_yes=True, # Auto-confirm actions
answer_keep=False # Remove fragments after build
)Towncrier uses a modular architecture with these key components:
The workflow involves creating individual fragment files for each change, then running the build command to combine them into a cohesive changelog entry.
Build a combined news file from news fragments, with options for drafts, custom versions, and fragment management.
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
) -> NoneCreate new news fragments with customizable content, sections, and automatic editor integration.
def __main(
ctx: click.Context,
directory: str | None,
config_path: str | None,
filename: str,
edit: bool | None,
content: str,
section: str | None
) -> NoneCheck for new fragments on a branch by comparing with a base branch and validating fragment requirements.
def __main(
comparewith: str | None,
directory: str | None,
config_path: str | None,
staged: bool
) -> NoneCore functionality for finding, parsing, and rendering news fragments with support for various formats and organization.
def find_fragments(
base_directory: str,
config: Config,
strict: bool = False
) -> tuple[dict[str, dict[tuple[str, str, int], str]], list[tuple[str, str]]]
def render_fragments(
template: str,
issue_format: str | None,
fragments: Mapping[str, Mapping[str, Mapping[str, Sequence[str]]]],
definitions: Mapping[str, Mapping[str, Any]],
underlines: Sequence[str],
wrap: bool,
versiondata: Mapping[str, str],
top_underline: str = "=",
all_bullets: bool = False,
render_title: bool = True,
md_header_level: int = 1
) -> strLoad and manage towncrier configuration from TOML files with validation and defaults.
def load_config_from_options(
directory: str | None,
config_path: str | None
) -> tuple[str, Config]
class Config:
sections: Mapping[str, str]
types: Mapping[str, Mapping[str, Any]]
template: str | tuple[str, str]
start_string: str
package: str
package_dir: str
single_file: bool
filename: str
directory: str | None
version: str | None
name: str
title_format: str | Literal[False]
issue_format: str | None
underlines: Sequence[str]
wrap: bool
all_bullets: bool
orphan_prefix: str
create_eof_newline: bool
create_add_extension: bool
ignore: list[str] | None
issue_pattern: strExtract project metadata like version and name from packages for automatic changelog generation.
def get_version(package_dir: str, package: str) -> str
def get_project_name(package_dir: str, package: str) -> strVersion control system integration for fragment management, branch operations, and news file staging.
def remove_files(base_directory: str, fragment_filenames: list[str]) -> None
def stage_newsfile(directory: str, filename: str) -> None
def get_remote_branches(base_directory: str) -> list[str]
def get_default_compare_branch(
base_directory: str,
branches: Container[str]
) -> str | None