Skip to main content

Hatch Build Scripts

PyPI - Version PyPI - Python Version License: MIT

A plugin for Hatch that allows you to run arbitrary build scripts and include their artifacts in your package distributions.

Installation

To set up hatch-build-scripts for your project you'll need to configure it in your project's pyproject.toml file as a build-system requirement:

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

Usage

Now you'll need to configure the build scripts you want to run. This is done by adding an array of scripts to the tool.hatch.build.hooks.build-scripts.scripts key in your pyproject.toml file. Each script is configured with the following keys:

Key Default Description
commands required An array of commands to run. Each command is run in a separate shell.
artifacts [] An array of artifact patterns (same as .gitignore) to include in your package distributions.
out_dir "." The directory to copy artifacts into.
work_dir "." The directory to run the commands in. All artifact patterns are relative to this directory.
clean_artifacts true Whether to clean files from the out_dir that match the artifact patterns before running the commands.
clean_out_dir false Whether to clean the out_dir before running the commands.

In practice this looks like:

[[tool.hatch.build.hooks.build-scripts.scripts]]
out_dir = "out"
commands = [
    "echo 'Hello, world!' > hello.txt",
    "echo 'Goodbye, world!' > goodbye.txt",
]
artifacts = [
    "hello.txt",
    "goodbye.txt",
]

[[tool.hatch.build.hooks.build-scripts.scripts]]
# you can add more scripts here...

You can configure script defaults for scripts by adding a [tool.hatch.build.hooks.build-scripts] table to your pyproject.toml file. The following keys are supported:

Key Default Description
out_dir "." The directory to copy artifacts into.
work_dir "." The directory to run the commands in. All artifact patterns are relative to this directory.
clean_artifacts true Whether to clean files from the out_dir that match the artifact patterns before running the commands.
clean_out_dir false Whether to clean the out_dir before running the commands.

Release files for hatch_build_scripts 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hatch_build_scripts 1.0.0
File Size Uploaded
hatch_build_scripts-1.0.0.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hatch_build_scripts 1.0.0
File Interpreter ABI Platform
hatch_build_scripts-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / hatch_build_scripts-1.0.0.tar.gz

Download URL hatch_build_scripts-1.0.0.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
563735e2f265c9e1b92dece6f762309114505ffaf6e5d51d462eb6a3b4f14640
BLAKE2b-256 checksum
How to use checksums
c794d5364975d18dff4f7b26e0a1623df6a3a74efbb616a509bd6dc051a0a700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release files / hatch_build_scripts-1.0.0-py3-none-any.whl

Download URL hatch_build_scripts-1.0.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22a13deee7213646b13351ed05fe9e47f036565d87d8f23d90d8980a63adb71a
BLAKE2b-256 checksum
How to use checksums
bd82c550623f6e76bf567f1cb3a84660e037e603979feaec7b8c88c2138bc64b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page