release.py


Overview

The `release.py` file provides a set of command-line driven utilities designed to automate and streamline the software release process for the project. Its main functionalities include generating release announcement documentation, regenerating example outputs in the docs, fixing code formatting, checking documentation links, and preparing a full pre-release cycle including git tagging and committing.

This file primarily interacts with:

By encapsulating these tasks, `release.py` helps maintain release consistency and automation, reducing manual errors and effort.


Detailed Descriptions

Functions


announce(version: str, template_name: str, doc_version: str) -> None

**Purpose:** Generates a new release announcement file in the documentation based on a provided template. It collects the list of authors and co-authors from git commit history since the last version tag, formats the contributors list, and inserts it into the announcement file.

**Parameters:**

**Returns:**

**Usage Example:**

announce("1.2.0", "release_template.rst", "1.2")

**Implementation details:**


regen(version: str) -> None

**Purpose:** Invokes the `tox` environment `regen` to update documentation examples and pytest outputs, ensuring docs reflect the current code state.

**Parameters:**

**Returns:**

**Usage Example:**

regen("1.2.0")

**Implementation details:**


fix_formatting() -> None

**Purpose:** Runs `pre-commit` hooks on all files to fix code formatting and linting issues automatically.

**Returns:**

**Usage Example:**

fix_formatting()

**Implementation details:**


check_links() -> None

**Purpose:** Runs Sphinx documentation build with a special environment to verify that all links in the docs are valid.

**Returns:**

**Usage Example:**

check_links()

**Implementation details:**


pre_release(version: str, template_name: str, doc_version: str, *, skip_check_links: bool) -> None

**Purpose:** Runs a full pre-release workflow that:

**Parameters:**

**Returns:**

**Usage Example:**

pre_release("1.2.0", "release_template.rst", "1.2", skip_check_links=False)

**Implementation details:**


changelog(version: str, write_out: bool = False) -> None

**Purpose:** Generates or drafts changelog entries using `towncrier`.

**Parameters:**

**Returns:**

**Usage Example:**

changelog("1.2.0", write_out=True)

**Implementation details:**


main() -> None

**Purpose:** Entry point for the script when run from the command line.

**Returns:**

**Usage:** From the shell:

python release.py 1.2.0 release_template.rst 1.2 --skip-check-links

**Implementation details:**


Implementation Highlights


Interaction with Other System Components


Visual Diagram

flowchart TD
    main --> pre_release
    pre_release --> announce
    pre_release --> regen
    pre_release --> changelog
    pre_release --> fix_formatting
    pre_release --> check_links
    announce --> git_describe[git describe]
    announce --> git_log_authors[git log authors]
    announce --> git_log_coauthors[git log co-authors]
    announce --> read_template[Read Template File]
    announce --> write_announcement[Write release-{version}.rst]
    announce --> update_index[Update index.rst]
    regen --> tox_regen[tox -e regen]
    fix_formatting --> pre_commit[pre-commit run --all-files]
    check_links --> tox_checklinks[tox -e docs-checklinks]
    changelog --> towncrier_build[towncrier build]
    pre_release --> git_commit[git commit -a -m "Prepare release version"]

Summary

The `release.py` file is a utility script designed to automate the routine tasks involved in preparing a software release, including generating documentation announcements, updating changelogs, ensuring formatting standards, checking documentation integrity, and managing git commits and tags. The script integrates tightly with git, documentation files, and external tools to provide a seamless pre-release workflow driven by a simple command-line interface.