pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
6.11k stars 309 forks source link

What is the canonical way to specify the packages to distribute? #1692

Open laclouis5 opened 3 months ago

laclouis5 commented 3 months ago

I'm quite confused by the Introduction Walkthrough. The hatch new "Hatch Demo" command used to showcase how to setup and build a project with hatch seems to setup a src-layout project which have this structure (presented in the tutorial):

hatch-demo
├── src
│   └── hatch_demo
│       ├── __about__.py
│       └── __init__.py
├── tests
│   └── __init__.py
├── LICENSE.txt
├── README.md
└── pyproject.toml

However, the generated pyproject.toml does not seem to take this src-layout into account: building this example project with the hatch build command generates a source distribution that contains the tests/ data and basically everything in the root directory.

I don't think that this default behavior is well understood and adequate. I think that at least the tutorial should be updated to better inform people of this choice. Anyway, I tried to find a workaround for this issue but the solutions are still unclear to me. Multiple solutions were discussed here and I ended up using this:

[tool.hatch.build.targets.sdist]
packages = ["src/hatch_demo"]

Is this workaround correct or is there a canonical way to specify where to find the packages to distribute in the configuration?

timonviola commented 2 months ago

I use this in my projects:


[tool.hatch.build.targets.sdist]
exclude = [
  "/.*",
  "/docs",
  "/tests"
]

[tool.hatch.build.targets.wheel]
packages = ["src/my-package"]

I hope it helps docs