Skip to content

Commit 2af41c5

Browse files
authored
Merge pull request #9226 from bluetech/doc-setup-py
doc: modernize discussion of setup.py in "Good Integration Practices"
2 parents 61e506a + 7314b32 commit 2af41c5

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

doc/en/explanation/goodpractices.rst

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,43 @@ pip_ for installing your application and any dependencies,
1212
as well as the ``pytest`` package itself.
1313
This ensures your code and dependencies are isolated from your system Python installation.
1414

15-
Next, place a ``setup.py`` file in the root of your package with the following minimum content:
15+
Next, place a ``pyproject.toml`` file in the root of your package:
1616

17-
.. code-block:: python
17+
.. code-block:: toml
1818
19-
from setuptools import setup, find_packages
19+
[build-system]
20+
requires = ["setuptools>=42", "wheel"]
21+
build-backend = "setuptools.build_meta"
2022
21-
setup(name="PACKAGENAME", packages=find_packages())
23+
and a ``setup.cfg`` file containing your package's metadata with the following minimum content:
2224

23-
Where ``PACKAGENAME`` is the name of your package. You can then install your package in "editable" mode by running from the same directory:
25+
.. code-block:: ini
26+
27+
[metadata]
28+
name = PACKAGENAME
29+
30+
[options]
31+
packages = find:
32+
33+
where ``PACKAGENAME`` is the name of your package.
34+
35+
.. note::
36+
37+
If your pip version is older than ``21.3``, you'll also need a ``setup.py`` file:
38+
39+
.. code-block:: python
40+
41+
from setuptools import setup
42+
43+
setup()
44+
45+
You can then install your package in "editable" mode by running from the same directory:
2446

2547
.. code-block:: bash
2648
2749
pip install -e .
2850
2951
which lets you change your source code (both tests and application) and rerun tests at will.
30-
This is similar to running ``python setup.py develop`` or ``conda develop`` in that it installs
31-
your package using a symlink to your development code.
3252

3353
.. _`test discovery`:
3454
.. _`Python test discovery`:
@@ -68,7 +88,8 @@ to keep tests separate from actual application code (often a good idea):
6888

6989
.. code-block:: text
7090
71-
setup.py
91+
pyproject.toml
92+
setup.cfg
7293
mypkg/
7394
__init__.py
7495
app.py
@@ -82,7 +103,7 @@ This has the following benefits:
82103

83104
* Your tests can run against an installed version after executing ``pip install .``.
84105
* Your tests can run against the local copy with an editable install after executing ``pip install --editable .``.
85-
* If you don't have a ``setup.py`` file and are relying on the fact that Python by default puts the current
106+
* If you don't use an editable install and are relying on the fact that Python by default puts the current
86107
directory in ``sys.path`` to import your package, you can execute ``python -m pytest`` to execute the tests against the
87108
local copy directly, without using ``pip``.
88109

@@ -103,7 +124,8 @@ If you need to have test modules with the same name, you might add ``__init__.py
103124

104125
.. code-block:: text
105126
106-
setup.py
127+
pyproject.toml
128+
setup.cfg
107129
mypkg/
108130
...
109131
tests/
@@ -130,7 +152,8 @@ sub-directory of your root:
130152

131153
.. code-block:: text
132154
133-
setup.py
155+
pyproject.toml
156+
setup.cfg
134157
src/
135158
mypkg/
136159
__init__.py
@@ -167,7 +190,8 @@ want to distribute them along with your application:
167190

168191
.. code-block:: text
169192
170-
setup.py
193+
pyproject.toml
194+
setup.cfg
171195
mypkg/
172196
__init__.py
173197
app.py
@@ -191,11 +215,11 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
191215

192216
.. note::
193217

194-
You can use Python3 namespace packages (PEP420) for your application
218+
You can use namespace packages (PEP420) for your application
195219
but pytest will still perform `test package name`_ discovery based on the
196220
presence of ``__init__.py`` files. If you use one of the
197221
two recommended file system layouts above but leave away the ``__init__.py``
198-
files from your directories it should just work on Python3.3 and above. From
222+
files from your directories, it should just work. From
199223
"inlined tests", however, you will need to use absolute imports for
200224
getting at your application code.
201225

@@ -230,8 +254,6 @@ Note that this layout also works in conjunction with the ``src`` layout mentione
230254
much less surprising.
231255

232256

233-
.. _`virtualenv`: https://pypi.org/project/virtualenv/
234-
.. _`buildout`: http://www.buildout.org/en/latest/
235257
.. _pip: https://pypi.org/project/pip/
236258

237259
.. _`use tox`:

0 commit comments

Comments
 (0)