Skip to content

Release

invoke_tasklib.release

Build and publish tasks (release.*) of the PyPI package.

release.build builds the wheel and the source distribution with uv build and verifies that each one installs and imports. release.publish checks the git state, builds, and uploads with uv publish to PyPI or TestPyPI. The credentials are read from the environment and never appear on a command line.

invoke_tasklib.release.NAMESPACE module-attribute

NAMESPACE = 'release'

The name of the namespace of the tasks of this module.

invoke_tasklib.release.build

build(
    c: Context,
    *,
    check: bool = False,
    args: str | None = None,
) -> None

Build the package and verify the built artifacts.

The artifacts are checked to be installable. The newest wheel and the newest source distribution in the output directory (dist/, or --out-dir of --args) are each installed in an isolated environment and the package is imported from it, using package.import_name. The import runs in isolated mode (python -I), so the current directory is not on sys.path: a package of the source tree (flat layout) cannot hide an artifact that does not contain it. Only the kinds that the build produces are verified: with --wheel or --sdist in --args, the other kind is not.

Parameters:

Name Type Description Default
c Context

The invoke context.

required
check bool

If True, also check the package's PyPI metadata with twine. Default is False.

False
args str | None

Extra arguments passed to uv build.

None

invoke_tasklib.release.publish

publish(
    c: Context,
    *,
    test_pypi: bool = False,
    dry_run: bool = False,
    yes: bool = False,
    skip_checks: bool = False,
    args: str | None = None,
) -> None

Build and publish the package to PyPI.

Before anything is built, the task checks that the working tree is clean, that HEAD is tagged and that the tag matches the pyproject.toml version (--skip-checks turns it off). Outside of CI (CI set to something other than 0 and false) it then asks for a confirmation (--yes turns it off).

The credentials are either a token or, in GitHub Actions with the id-token: write permission, PyPI Trusted Publishing. The token is read from PYPI_TOKEN (from TEST_PYPI_TOKEN with --test-pypi, so a PyPI token is never sent to TestPyPI) or, without --test-pypi only, from UV_PUBLISH_TOKEN, which uv publish reads natively. It is passed to uv publish through its environment, so it does not appear on the command line. The credential variables that uv publish reads (UV_PUBLISH_TOKEN, UV_PUBLISH_USERNAME and UV_PUBLISH_PASSWORD) are removed from its environment, and only the chosen token is given, so a token meant for PyPI is never sent to TestPyPI. dist/ is cleared by the build, so only the freshly built artifacts are uploaded.

The build is the one of release.build, run with its defaults: args is given to uv publish only.

Parameters:

Name Type Description Default
c Context

The invoke context.

required
test_pypi bool

If True, publish to TestPyPI.

False
dry_run bool

If True, run the checks and the build, and give --dry-run to uv publish. No credentials are needed.

False
yes bool

If True, do not ask for a confirmation.

False
skip_checks bool

If True, do not check the git state.

False
args str | None

Extra arguments passed to uv publish.

None

Raises:

Type Description
Exit

If the git state is not releasable, if there are no credentials, or if the confirmation is refused.