Skip to content

Commit 2ff089b

Browse files
authored
Merge pull request #1331 from sinoroc/add-setup-py-deprecated
Add discussion "Is setup.py deprecated?"
2 parents 74c509f + 1415c8d commit 2ff089b

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

source/discussions/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ specific topic. If you're just trying to get stuff done, see
1313
install-requires-vs-requirements
1414
wheel-vs-egg
1515
src-layout-vs-flat-layout
16+
setup-py-deprecated
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
.. _setup-py-deprecated:
2+
3+
4+
===========================
5+
Is ``setup.py`` deprecated?
6+
===========================
7+
8+
No, :term:`setup.py` is not deprecated,
9+
it is a valid configuration file for :ref:`setuptools`
10+
that happens to be written in Python, instead of in *TOML* for example
11+
(a similar practice is used by other tools
12+
like *nox* and its :file:`nox.py` configuration file,
13+
or *pytest* and :file:`conftest.py`).
14+
15+
And of course *setuptools* itself is not deprecated either.
16+
17+
It is however deprecated to run ``python setup.py`` as a command line tool.
18+
19+
This means for example that the following commands **MUST NOT** be run anymore:
20+
21+
* ``python setup.py install``
22+
* ``python setup.py develop``
23+
* ``python setup.py sdist``
24+
* ``python setup.py bdist_wheel``
25+
26+
27+
What commands should be used instead?
28+
=====================================
29+
30+
+---------------------------------+----------------------------------------+
31+
| Deprecated | Current recommendation |
32+
+=================================+========================================+
33+
| ``python setup.py install`` | ``python -m pip install .`` |
34+
+---------------------------------+----------------------------------------+
35+
| ``python setup.py develop`` | ``python -m pip install --editable .`` |
36+
+---------------------------------+----------------------------------------+
37+
| ``python setup.py sdist`` | ``python -m build`` [#needs-build]_ |
38+
+---------------------------------+ |
39+
| ``python setup.py bdist_wheel`` | |
40+
+---------------------------------+----------------------------------------+
41+
42+
43+
.. [#needs-build] This requires the :ref:`build` dependency.
44+
It is recommended to always build and publish both the source distribution
45+
and wheel of a project, which is what ``python -m build`` does.
46+
If necessary the ``--sdist`` and ``--wheel`` options can be used
47+
to generate only one or the other.
48+
49+
50+
In order to install a setuptools based project,
51+
it was common to run :file:`setup.py`'s ``install`` command such as:
52+
``python setup.py install``.
53+
Nowadays, the recommended method is to use :ref:`pip` directly
54+
with a command like this one: ``python -m pip install .``.
55+
Where the dot ``.`` is actually a file system path,
56+
it is the path notation for the current directory.
57+
Indeed, *pip* accepts a path to
58+
a project's source tree directory on the local filesystem
59+
as argument to its ``install`` sub-command.
60+
So this would also be a valid command:
61+
``python -m pip install path/to/project``.
62+
63+
As for the installation in *develop* mode aka *editable* mode,
64+
instead of ``python setup.py develop``
65+
one can use the ``--editable`` option of pip's *install* sub-command:
66+
``python -m pip install --editable .``.
67+
68+
One recommended, simple, and straightforward method of building
69+
:term:`source distributions <Source Distribution (or "sdist")>`
70+
and :term:`wheels <Wheel>`
71+
is to use the :ref:`build` tool with a command like
72+
``python -m build``
73+
which triggers the generation of both distribution formats.
74+
If necessary the ``--sdist`` and ``--wheel`` options can be used
75+
to generate only one or the other.
76+
Note that the build tool needs to be installed separately.
77+
78+
The command ``python setup.py install`` was deprecated
79+
in setuptools version *58.3.0*.
80+
81+
82+
What about custom commands?
83+
===========================
84+
85+
Likewise, custom :file:`setup.py` commands are deprecated.
86+
The recommendation is to migrate those custom commands
87+
to a task runner tool or any other similar tool.
88+
Some examples of such tools are:
89+
chuy, make, nox or tox, pydoit, pyinvoke, taskipy, and thx.
90+
91+
92+
What about custom build steps?
93+
==============================
94+
95+
Custom build steps that for example
96+
either overwrite existing steps such as ``build_py``, ``build_ext``, and ``bdist_wheel``
97+
or add new build steps are not deprecated.
98+
Those will be automatically called as expected.
99+
100+
101+
Should ``setup.py`` be deleted?
102+
===============================
103+
104+
Although the usage of :file:`setup.py` as an executable script is deprecated,
105+
its usage as a configuration file for setuptools is absolutely fine.
106+
There is likely no modification needed in :file:`setup.py`.
107+
108+
.. todo::
109+
110+
Link to a "How to modernize a setup.py based project?"
111+
112+
113+
Is ``pyproject.toml`` mandatory?
114+
================================
115+
116+
While it is not technically necessary yet,
117+
it is **STRONGLY RECOMMENDED** for a project to have a :file:`pyproject.toml` file
118+
at the root of its source tree with a content like this:
119+
120+
.. code:: toml
121+
122+
[build-system]
123+
requires = ["setuptools"]
124+
build-backend = "setuptools.build_meta"
125+
126+
127+
.. todo::
128+
129+
Link to "How to modernize a setup.py based project?"
130+
131+
132+
The standard fallback behavior for a :term:`build frontend <Build Frontend>`
133+
in the absence of a :file:`pyproject.toml` file and its ``[build-system]`` table
134+
is to assume that the :term:`build backend <Build Backend>` is setuptools.
135+
136+
137+
Why? What does it all mean?
138+
===========================
139+
140+
One way to look at it is that the scope of setuptools
141+
has now been reduced to the role of a build backend.
142+
143+
144+
Where to read more about this?
145+
==============================
146+
147+
* https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html
148+
149+
* :doc:`setuptools:deprecated/commands`

0 commit comments

Comments
 (0)