uv: `uv build` with `hatchling` build backend doesn't include nested package in wheel
Summary
High level problem
I’m building a package using uv build and the resulting file doesn’t contain the package source files when it’s unzipped.
I noticed that it happened when I moved my python package from root directory into src directory and had to change the configuration to
[tool.hatch.build]
packages = ["src/<my_package>"]
sources = ["src"]
How to reproduce
Let’s consider following project: https://github.com/dbt-labs/dbt-adapters/tree/main/dbt-bigquery
Let’s prepare it with uv:
uv sync
uv build
Resulting dbt_bigquery-1.10.0a1-py3-none-any.whl in /dist doesn’t contain any source file ❌
Then if I try to use hatch directly:
uv add --dev hatch
uv run hatch build
Resulting dbt_bigquery-1.10.0a1-py3-none-any.whl in /dist contains source files as expected ✅
Workaround
As shown previously, using hatch directly through uv works:
uv run hatch build
Note
it wasn’t working either with an older uv version so I suspect it’s not a regression.
Platform
MacOS 15.3 ARM64
Version
uv 0.6.0 (591f38c25 2025-02-14)
Python version
Python 3.11.1
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (10 by maintainers)
I read https://packaging.python.org/en/latest/discussions/package-formats/ to try to understand both. It’s not explicit if it should be mapping the repository file structure or if it should map the package structure. Asking ChatGPT, it points out it should map the repository structure, in which case, the configuration you suggested and that works with both tools is the “right one”.
I confirm that:
works as intended and produced the same artifacts for
uvandhatch👍 I’ll suggest the change on the linked repository, thanks @ofek & @zanieb!(Thanks @ofek!)
Here is the example configuration I gave you, replacing
<my_package>with the actual directory name: