-
Notifications
You must be signed in to change notification settings - Fork 282
Use pyproject.toml with hatchling instead of setuptools
#2138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Use pyproject.toml with hatchling instead of setuptools
#2138
Conversation
The main motivation for this change is to migrate from the non-standard `setup.py` to the standard PEP 517 `setup.py`. The secondary motivation is to use a build backend that's easier to use and harder to get wrong than setuptools. Hatchling is the most popular build backend behind setuptools (I can provide data if required), and much easier to use than setuptools. Notably, it will include `py.typed` and `.pyi` files automatically. This also applies to most other build backends. This means we can remove the setuptools-specific documentation. packaging.python.org has a tab system to show different build backends (https://packaging.python.org/en/latest/guides/writing-pyproject-toml/). Afaik typing.python.org doesn't, so we only show one build backend. Fixes python#2121
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/my_great_package-stubs"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uv-build supports those without extra configuration, but hatchling is wider used.
| It's important to ensure that the ``py.typed`` marker file is included in the | ||
| distributed package. If using ``setuptools``, this can be achieved like so: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note is afaik only relevant for setuptools anymore. Since the other build backends I'm aware support this in the default configuration, I've shortened it to this hint, the specifics fit better in the setuptools documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather make a general statement, instead of focusing on hatchling. Something like "Most modern build tools like hatchling include it by default."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setuptools>=69 includes this by default too, so I think we can just remove this statement / I think we can just not mention build backends in this guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shrunk the note to mentioning it needs to be included and all modern package managers do it by default, i.e. don't put it in your gitignore where hatchling skips it.
|
With the latest iteration, only the stubs package has a |
hauntsaninja
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should try to stay build backend agnostic, unless one build backend provides a better experience for typing.
Based on that, I think we should entirely remove:
It's important to ensure that the
py.typedmarker file is included in the
distributed package. Modern build backends such ashatchlinginclude it by default
And while we're here, maybe replace it with:
Note the py.typed should be located inside the package, along with
__init__.py
since I've seen people put it a layer above sometimes.
For the stubs-only package, I'd vote we change the example to uv-build because that's a better experience for these users. If hatchling later adds the same feature, then we can edit to mention that.
Do you still want to show the [project]
name = "my-great-package-stubs"
version = "0.1.0"
requires-python = ">=3.14"
[build-system]
requires = ["uv_build>=0.9.18,<0.10.0"]
build-backend = "uv_build" |
The main motivation for this change is to migrate from the non-standard
setup.pyto the standard PEP 517setup.py. The secondary motivation is to use a build backend that's easier to use and harder to get wrong than setuptools.Hatchling is the most popular build backend behind setuptools (I can provide data if required), and much easier to use than setuptools. Notably, it will include
py.typedand.pyifiles automatically. This also applies to most other build backends. This means we can remove the setuptools-specific documentation.packaging.python.org has a tab system to show different build backends (https://packaging.python.org/en/latest/guides/writing-pyproject-toml/). Afaik typing.python.org doesn't, so we only show one build backend.
Fixes #2121