1+ :orphan:
2+
13.. _setup-py-deprecated :
24
35
@@ -9,207 +11,10 @@ No, :term:`setup.py` and :ref:`setuptools` are not deprecated.
911
1012Setuptools is perfectly usable as a :term: `build backend `
1113for packaging Python projects.
12- And :file: `setup.py ` is a valid configuration file for :ref: `setuptools `
13- that happens to be written in Python, instead of in *TOML * for example
14- (a similar practice is used by other tools
15- like *nox * and its :file: `noxfile.py ` configuration file,
16- or *pytest * and :file: `conftest.py `).
17-
18- However, ``python setup.py `` and the use of :file: `setup.py `
19- as a command line tool are deprecated.
20-
21- This means that commands such as the following **MUST NOT ** be run anymore:
22-
23- * ``python setup.py install ``
24- * ``python setup.py develop ``
25- * ``python setup.py sdist ``
26- * ``python setup.py bdist_wheel ``
27-
28-
29- What commands should be used instead?
30- =====================================
31-
32- +---------------------------------+----------------------------------------+
33- | Deprecated | Recommendation |
34- +=================================+========================================+
35- | ``python setup.py install `` | ``python -m pip install . `` |
36- +---------------------------------+----------------------------------------+
37- | ``python setup.py develop `` | ``python -m pip install --editable . `` |
38- +---------------------------------+----------------------------------------+
39- | ``python setup.py sdist `` | ``python -m build `` [#needs-build ]_ |
40- +---------------------------------+ |
41- | ``python setup.py bdist_wheel `` | |
42- +---------------------------------+----------------------------------------+
43-
44-
45- .. [#needs-build ] This requires the :ref: `build ` dependency.
46- It is recommended to always build and publish both the source distribution
47- and wheel of a project, which is what ``python -m build `` does.
48- If necessary the ``--sdist `` and ``--wheel `` options can be used
49- to generate only one or the other.
50-
51-
52- In order to install a setuptools based project,
53- it was common to run :file: `setup.py `'s ``install `` command such as:
54- ``python setup.py install ``.
55- Nowadays, the recommended method is to use :ref: `pip ` directly
56- with a command like this one: ``python -m pip install . ``.
57- Where the dot ``. `` is actually a file system path,
58- it is the path notation for the current directory.
59- Indeed, *pip * accepts a path to
60- a project's source tree directory on the local filesystem
61- as argument to its ``install `` sub-command.
62- So this would also be a valid command:
63- ``python -m pip install path/to/project ``.
64-
65- As for the installation in *develop * mode aka *editable * mode,
66- instead of ``python setup.py develop ``
67- one can use the ``--editable `` option of pip's *install * sub-command:
68- ``python -m pip install --editable . ``.
69-
70- One recommended, simple, and straightforward method of building
71- :term: `source distributions <Source Distribution (or "sdist")> `
72- and :term: `wheels <Wheel> `
73- is to use the :ref: `build ` tool with a command like
74- ``python -m build ``
75- which triggers the generation of both distribution formats.
76- If necessary the ``--sdist `` and ``--wheel `` options can be used
77- to generate only one or the other.
78- Note that the build tool needs to be installed separately.
79-
80- The command ``python setup.py install `` was deprecated
81- in setuptools version *58.3.0 *.
82-
83-
84- What about other commands?
85- ==========================
86-
87- What are some replacements for the other ``python setup.py `` commands?
88-
89-
90- ``python setup.py test ``
91- ------------------------
92-
93- The recommendation is to use a test runner such as pytest _.
94-
95- .. _pytest : https://docs.pytest.org/
96-
97-
98- ``python setup.py check ``, ``python setup.py register ``, and ``python setup.py upload ``
99- ---------------------------------------------------------------------------------------
100-
101- A trusted replacement is :ref: `twine `:
102-
103- * ``python -m twine check --strict dist/* ``
104- * ``python -m twine register dist/*.whl `` [#not-pypi ]_
105- * ``python -m twine upload dist/* ``
106-
107- .. [#not-pypi ] Not necessary, nor supported on :term: `PyPI <Python Package Index (PyPI)> `.
108- But might be necessary on other :term: `package indexes <package index> ` (for example :ref: `devpi `).
109-
110-
111- ``python setup.py --version ``
112- -----------------------------
113-
114- A possible replacement solution (among others) is to rely on setuptools-scm _:
115-
116- * ``python -m setuptools_scm ``
117-
118- .. _setuptools-scm : https://setuptools-scm.readthedocs.io/latest/usage/#as-cli-tool
119-
120-
121- Remaining commands
122- ------------------
123-
124- This guide does not make suggestions of replacement solutions for those commands:
125-
126- .. hlist ::
127- :columns: 4
128-
129- * ``alias ``
130- * ``bdist ``
131- * ``bdist_dumb ``
132- * ``bdist_egg ``
133- * ``bdist_rpm ``
134- * ``build ``
135- * ``build_clib ``
136- * ``build_ext ``
137- * ``build_py ``
138- * ``build_scripts ``
139- * ``clean ``
140- * ``dist_info ``
141- * ``easy_install ``
142- * ``editable_wheel ``
143- * ``egg_info ``
144- * ``install_data ``
145- * ``install_egg_info ``
146- * ``install_headers ``
147- * ``install_lib ``
148- * ``install_scripts ``
149- * ``rotate ``
150- * ``saveopts ``
151- * ``setopt ``
152- * ``upload_docs ``
153-
154-
155- What about custom commands?
156- ===========================
157-
158- Likewise, custom :file: `setup.py ` commands are deprecated.
159- The recommendation is to migrate those custom commands
160- to a task runner tool or any other similar tool.
161- Some examples of such tools are:
162- chuy, make, nox or tox, pydoit, pyinvoke, taskipy, and thx.
163-
164-
165- What about custom build steps?
166- ==============================
167-
168- Custom build steps that for example
169- either overwrite existing steps such as ``build_py ``, ``build_ext ``, and ``bdist_wheel ``
170- or add new build steps are not deprecated.
171- Those will be automatically called as expected.
172-
173-
174- Should ``setup.py `` be deleted?
175- ===============================
176-
177- Although the usage of :file: `setup.py ` as an executable script is deprecated,
178- its usage as a configuration file for setuptools is absolutely fine.
179- There is likely no modification needed in :file: `setup.py `.
180-
181-
182- Is ``pyproject.toml `` mandatory?
183- ================================
184-
185- While it is not technically necessary yet,
186- it is **STRONGLY RECOMMENDED ** for a project to have a :file: `pyproject.toml ` file
187- at the root of its source tree with a content like this:
188-
189- .. code :: toml
190-
191- [build-system]
192- requires = ["setuptools"]
193- build-backend = "setuptools.build_meta"
194-
195-
196- The guide :ref: `modernize-setup-py-project ` has more details about this.
197-
198- The standard fallback behavior for a :term: `build frontend <Build Frontend> `
199- in the absence of a :file: `pyproject.toml ` file and its ``[build-system] `` table
200- is to assume that the :term: `build backend <Build Backend> ` is setuptools.
201-
202-
203- Why? What does it all mean?
204- ===========================
205-
206- One way to look at it is that the scope of setuptools
207- has now been reduced to the role of a build backend.
208-
209-
210- Where to read more about this?
211- ==============================
21214
213- * `Why you shouldn't invoke setup.py directly <https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html >`__ by Paul Ganssle
15+ Only invoking ``python setup.py <command> `` directly is deprecated. For more
16+ details on that topic, please see:
21417
18+ * `Why you shouldn't invoke setup.py directly <https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html >`__
19+ by Paul Ganssle
21520* :doc: `setuptools:deprecated/commands `
0 commit comments