Hatch Build Scripts Plugin

1.0.0 · active · verified Thu Apr 16

Hatch Build Scripts is a plugin for Hatch, the modern Python project manager, designed to allow users to execute arbitrary shell commands during the build process and include their generated artifacts directly within package distributions. It extends Hatch's build capabilities, providing a flexible way to automate tasks such as compiling assets or generating code, ensuring these outputs are properly bundled. The current stable version is 1.0.0, and releases follow an as-needed cadence to add features and fix bugs.

Common errors

Warnings

Install

Imports

Quickstart

To integrate `hatch-build-scripts`, add it to your project's `build-system.requires` in `pyproject.toml`. Then, define scripts under `[[tool.hatch.build.hooks.build-scripts.scripts]]` with `commands` to execute and `artifacts` patterns (like .gitignore) to include in your package. The `out_dir` specifies where artifacts should be placed within the build context.

# pyproject.toml
[build-system]
requires = ["hatchling", "hatch-build-scripts"]
build-backend = "hatchling.build"

[project]
name = "my-project"
version = "0.1.0"

[[tool.hatch.build.hooks.build-scripts.scripts]]
out_dir = "src/my_project"
commands = [
    "echo 'Hello from build script!' > generated_file.txt",
    "python -c \"print('__version__ = \'0.1.0\'')\" > _version.py"
]
artifacts = [
    "generated_file.txt",
    "_version.py"
]

# To run the build:
# hatch build --clean

view raw JSON →