Registry / devops / hatch-build-scripts

hatch-build-scripts

JSON →
library1.0.0pypypiunverified

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.

pip install hatch-build-scripts
INSTALL
IMPORT
SIG · HATCH-BUILD-SCRIPT
H
hatch-build-scripts
devopspythonv1.0.0
Install
2.0s avg
Import
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.0s · import 0.000s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Build hook configuration
This plugin is configured in `pyproject.toml` under `[tool.hatch.build.hooks.build-scripts]`. It does not require direct Python `import` statements in user code.
Hatch plugins are typically configured declaratively rather than imported programmatically.

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
Debug
Known issues
gotchaThe PyPI project summary 'Dependency injection without the boilerplate.' is misleading. The actual purpose of `hatch-build-scripts` is to run arbitrary shell commands and include their outputs (artifacts) during a Hatch build, as described in its detailed documentation.
fix
Refer to the GitHub repository or the detailed PyPI description for the correct understanding of the plugin's functionality.
affects: All versions
gotchaIncorrect `pyproject.toml` configuration is a common pitfall. Ensure `hatch-build-scripts` is listed in `build-system.requires` and `tool.hatch.build.hooks.build-scripts` section is correctly formatted with `commands` and `artifacts` keys.
fix
Carefully review the `quickstart` example and the official documentation for correct TOML syntax and required keys.
affects: All versions
gotchaOn Windows, `hatch build` can fail silently with no output if an IDE (like VS Code) or another process is locking files within the build environment. This prevents Hatch from modifying necessary files.
fix
Ensure all IDEs and other applications are closed before running `hatch build`. If the issue persists, try deleting the Hatch cache directory (e.g., `C:\Users\{USERNAME}\AppData\Local\hatch`).
affects: All versions
deprecatedThe `clean_artifacts` parameter in script configuration was introduced in v1.0.0 and defaults to `true`. In older versions, artifacts might not have been cleaned by default, which could lead to stale files being included.
fix
Upgrade to `hatch-build-scripts>=1.0.0` to leverage automatic artifact cleaning. If on older versions, manually manage artifact cleanup via custom commands.
affects: <1.0.0
Upgrade
Version history
1.0.0latest on PyPI · released May 29, 2025
Audit
Dependencies
hatchlingrequiredRequired build backend, typically listed in `build-system.requires` in `pyproject.toml`.
hatchrequiredThe core project manager that orchestrates the build process and utilizes this plugin.
Agent activity
7 hits · last 30 days
node
6
Google (search)
1
Resources
hatch-build-scripts — pip install hatch-build-scripts · libregistry