hatch_build
Writes the build stamp that :mod:easyfabric.buildinfo reports.
Runs as a hatchling build hook, so every wheel carries the moment it was built —
a local hatch build just as much as a pipelineAn automated "conveyor belt" that moves data from one place to another or performs a task automatically. run. The pipeline adds what
only it knows: the commit it built from and its build number, passed in through
the environment. Locally the commit is read from git when the source is a
checkout, so a hand-built wheel is traceable too.
Nothing here fails a build: a missing git, a detached environment or an
unwritable path leaves the corresponding field None rather than stopping the
release. The build backend is imported optionally so the stamp helpers — and the
tests covering them — stay importable in an environment without hatchling.
git_environment
def git_environment() -> dict[str, str]
Returns the environment for the git call, without the GIT_* variables.
A build started from a git hook — or any process that exported GIT_DIR —
would otherwise have git answer for that repository whatever directory it
is asked about, stamping a commit the built source never came from.
resolve_commit
def resolve_commit(environment: dict[str, str], root: str) -> str | None
Returns the commit to stamp: what the build environment declares, else what
git says about the source tree, else None.
stamp_source
def stamp_source(commit: str | None, build_number: str | None,
built_at: str) -> str
Renders the stamp module as Python source.
existing_stamp
def existing_stamp(root: str) -> dict[str, str | None]
Returns the stamp already present in the source being packaged, if any.
uv build without arguments builds the sdist first and then the wheel
from that sdist, in a temporary directory where git cannot answer. The
sdist carries the stamp written while the checkout was still at hand, so
that answer has to survive the second build rather than be blanked.
resolve_stamp
def resolve_stamp(environment: dict[str, str],
root: str) -> tuple[str | None, str | None]
Returns the commit and build number to stamp, preferring what this build can determine and falling back per field to the stamp the source already carries.
stamp_summary
def stamp_summary(commit: str | None, build_number: str | None,
built_at: str) -> str
Renders the stamp as one line for the build output.
Printed rather than left to the wheel alone, so uv build and
hatch build say on the spot which build they just made — the question
this whole mechanism exists to answer.
CustomBuildHook Objects
class CustomBuildHook(BuildHookInterface)
Writes :data:STAMP_PATH before the wheel is assembled.