CI/CD | |
Package | |
Meta |
This provides a build hook plugin for Hatch that injects code into an installation that will automatically run before the first import.
Table of Contents
The build hook plugin name is autorun
.
-
pyproject.toml
[tool.hatch.build.targets.wheel.hooks.autorun] dependencies = ["hatch-autorun"]
-
hatch.toml
[build.targets.wheel.hooks.autorun] dependencies = ["hatch-autorun"]
You can select a relative path to a file containing the code with the file
option:
[tool.hatch.build.targets.wheel.hooks.autorun]
file = "resources/code.emded"
You can define the code itself with the code
option:
[tool.hatch.build.targets.wheel.hooks.autorun]
code = """
import coverage
coverage.process_startup()
"""
The current implementation uses a .pth
file to execute the code. You can set the .pth
file template with the template
option, which will be formatted with a code
variable representing the code
option or the contents of the file defined by the file
option. The following shows the default template:
[tool.hatch.build.targets.wheel.hooks.autorun]
template = "import os, sys;exec({code!r})"
Sometimes you'll only want builds to induce auto-run behavior when installed under certain circumstances, like for tests. In such cases, set the enable-by-default
option to false
:
[tool.hatch.build.targets.wheel.hooks.autorun]
enable-by-default = false
Then when the desired build conditions are met, set the HATCH_BUILD_HOOK_ENABLE_AUTORUN
environment variable to true
or 1
.
hatch-autorun
is distributed under the terms of the MIT license.