Skip to content

Commit 48945fa

Browse files
Use pyproject.toml instead of setup.py (#2138)
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. Modern build backends and much easier to use than setuptools, and will generally include `py.typed` and `.pyi` files automatically. This means we can remove the setuptools-specific documentation. We use `uv_build` for the stubs package example since it works out of the box with it. 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 --------- Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
1 parent 211b0cb commit 48945fa

File tree

1 file changed

+12
-55
lines changed

1 file changed

+12
-55
lines changed

docs/guides/libraries.rst

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,13 @@ A typical directory structure would look like:
8282

8383
.. code-block:: text
8484
85-
setup.py
85+
pyproject.toml
8686
my_great_package/
8787
__init__.py
8888
stuff.py
8989
py.typed
9090
91-
It's important to ensure that the ``py.typed`` marker file is included in the
92-
distributed package. If using ``setuptools``, this can be achieved like so:
93-
94-
.. code-block:: python
95-
96-
from setuptools import setup
97-
98-
setup(
99-
name="my_great_distribution",
100-
version="0.1",
101-
package_data={"my_great_package": ["py.typed"]},
102-
packages=["my_great_package"],
103-
)
104-
91+
Note the py.typed should be located inside the package, along with ``__init__.py``.
10592

10693
Type stub files included in the package
10794
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -113,27 +100,13 @@ directory structure would look like:
113100

114101
.. code-block:: text
115102
116-
setup.py
103+
pyproject.toml
117104
my_great_package/
118105
__init__.py
119106
stuff.py
120107
stuff.pyi
121108
py.typed
122109
123-
If using ``setuptools``, we can ensure the ``.pyi`` and ``py.typed`` files are
124-
included like so:
125-
126-
.. code-block:: python
127-
128-
from setuptools import setup
129-
130-
setup(
131-
name="my_great_distribution",
132-
version="0.1",
133-
package_data={"my_great_package": ["py.typed", "stuff.pyi"]},
134-
packages=["my_great_package"],
135-
)
136-
137110
The presence of ``.pyi`` files does not affect the Python interpreter at runtime
138111
in any way. However, static type checkers will only look at the ``.pyi`` file and
139112
ignore the corresponding ``.py`` file.
@@ -150,41 +123,25 @@ For example:
150123

151124
.. code-block:: text
152125
153-
setup.py
126+
pyproject.toml
154127
my_great_package-stubs/
155128
__init__.pyi
156129
stuff.pyi
157130
131+
.. code-block:: toml
158132
159-
.. code-block:: python
160-
161-
from setuptools import setup
162-
163-
setup(
164-
name="my_great_package-stubs",
165-
version="0.1",
166-
package_data={"my_great_package-stubs": ["__init__.pyi", "stuff.pyi"]},
167-
packages=["my_great_package-stubs"]
168-
)
133+
[project]
134+
name = "my-great-package-stubs"
135+
version = "0.1.0"
136+
requires-python = ">=3.10"
169137
138+
[build-system]
139+
requires = ["uv_build>=0.9.18,<0.10.0"]
140+
build-backend = "uv_build"
170141
171142
Users are then able to install the stubs-only package separately to provide
172143
types for the original library.
173144

174-
Inclusion in sdist
175-
^^^^^^^^^^^^^^^^^^
176-
177-
Note that to ensure inclusion of ``.pyi`` and ``py.typed`` files in an sdist
178-
(.tar.gz archive), you may also need to modify the inclusion rules in your
179-
``MANIFEST.in`` (see the
180-
`packaging guide <https://packaging.python.org/en/latest/guides/using-manifest-in/>`__
181-
for more details on ``MANIFEST.in``). For example:
182-
183-
.. code-block:: text
184-
185-
global-include *.pyi
186-
global-include py.typed
187-
188145
.. _type_completeness:
189146

190147
How much of my library needs types?

0 commit comments

Comments
 (0)