# Behavior traces — pypa/hatch

> Canonical page: https://codevetter.com/unpack/hatch/behavior-traces

# Behavior traces — pypa/hatch

Scanned commit 7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0 (2026-09-20). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

The source supports ordered walkthroughs of startup, command execution, environment persistence, artifact builds, and publishing. Conditions such as existing environments, skip-install, backend selection, and already-uploaded artifacts materially change the sequence. Environment execution is driven by a generator that prepares and runs work after the command handler populates its context. These are source traces, not observed execution results.
- Startup: main → hatch → Application → ConfigFile.restore if the default file is missing → ConfigFile.load → style initialization → storage directory selection → explicit or current-directory Project selection. — [src/hatch/cli/__init__.py#L127-L186](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/__init__.py#L127-L186) [src/hatch/cli/__init__.py#L241-L252](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/__init__.py#L241-L252) [src/hatch/config/user.py#L35-L57](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/config/user.py#L35-L57)
- Normal command execution: run parses ENV:ARGS → ctx.invoke(env.run) → parse_matrix_variables/select_environments → Application.runner_context → Project.get_environment → compatibility check only if the environment does not exist. — [src/hatch/cli/run/__init__.py#L150-L163](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/run/__init__.py#L150-L163) [src/hatch/cli/env/run.py#L80-L121](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/env/run.py#L80-L121) [src/hatch/cli/application.py#L119-L140](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/application.py#L119-L140) [src/hatch/project/core.py#L141-L180](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/core.py#L141-L180)
- Missing-environment preparation: managed_environment → metadata.reset → environment.create → optional pre-install commands → normal/editable project installation → optional post-install commands; skip-install bypasses the installation block. — [src/hatch/project/core.py#L182-L232](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/core.py#L182-L232) [src/hatch/env/virtual.py#L165-L203](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/env/virtual.py#L165-L203)
- Persistence after preparation: dependency_hash → EnvironmentMetadata.dependency_hash → optional generate_lockfile for locked inputs → dependencies_in_sync → optional sync_dependencies → update_dependency_hash → JSON write. — [src/hatch/project/core.py#L234-L256](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/core.py#L234-L256) [src/hatch/env/lock.py#L137-L166](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/env/lock.py#L137-L166) [src/hatch/project/env.py#L418-L443](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/env.py#L418-L443)
- Shell execution: execute_context applies context.env_vars → run_shell_commands enters command_context → resolve_commands/expand_command formats scripts → run_shell_command invokes the platform; parent SIGINT handling is restored in finally and exit-code policy is applied. — [src/hatch/cli/application.py#L54-L104](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/application.py#L54-L104) [src/hatch/cli/application.py#L151-L155](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/application.py#L151-L155) [src/hatch/env/plugin/interface.py#L963-L1010](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/env/plugin/interface.py#L963-L1010)
- Hatchling build: build → _build_project → prepare_build_environment → python -m hatchling build → build_impl selects builder → BuilderInterface.build validates metadata and initializes hooks → WheelBuilder.build_standard → finalize hooks → artifact yield. — [src/hatch/cli/build/__init__.py#L153-L208](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/build/__init__.py#L153-L208) [backend/src/hatchling/cli/build/__init__.py#L45-L93](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/backend/src/hatchling/cli/build/__init__.py#L45-L93) [backend/src/hatchling/builders/plugin/interface.py#L100-L176](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/backend/src/hatchling/builders/plugin/interface.py#L100-L176) [backend/src/hatchling/builders/wheel.py#L517-L541](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/backend/src/hatchling/builders/wheel.py#L517-L541)
- Alternative-backend build: prepare_build_environment gathers backend get_requires results → _build_project accepts only sdist/wheel → BuildFrontend generates and executes a hook script → output.json identifies the artifact → the frontend moves it to the requested directory. — [src/hatch/project/core.py#L274-L299](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/core.py#L274-L299) [src/hatch/cli/build/__init__.py#L165-L181](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/build/__init__.py#L165-L181) [src/hatch/project/frontend/core.py#L30-L76](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/project/frontend/core.py#L30-L76)
- Publish: CLI selects and checks the publisher → IndexPublisher resolves repository and credentials → recurse_artifacts reads metadata → simple API lookup skips existing filenames → upload_artifact sends new files → successful versions print URLs → write_updated_data persists prompted authentication. — [src/hatch/cli/publish/__init__.py#L101-L115](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/cli/publish/__init__.py#L101-L115) [src/hatch/publish/index.py#L63-L147](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/publish/index.py#L63-L147) [src/hatch/index/core.py#L64-L105](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/index/core.py#L64-L105) [src/hatch/publish/auth.py#L104-L116](https://github.com/pypa/hatch/blob/7c26ebeaf8b83f5f0374a2545bb15e36c87db0d0/src/hatch/publish/auth.py#L104-L116)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
