python-template
python-template copied to clipboard
use `python -m build` to build
Currently, the developer readme suggests to use python3 setup.py sdist bdist_wheel
to build packages, in a freshly created virtual environment too. The official Python packaging docs recommend using python -m build
. I think we should switch to this, also for consistency because explicit use of setup.py
is no longer recommended for installing the package either. Mainly though because it is a lot simpler; it creates the virtual environment itself and so makes the instructions a lot shorter.
This requires:
- Updating the README.dev.md instructions: replace almost all of the code in the first code block in subsection "2/3" with just
python -m build
(keeptwine
as well). - Adding the
build
package to thedev
extras section insetup.cfg
.
While we're at it, the instructions should also note that an account on PyPI and on TestPyPI (two separate accounts) are necessary for using twine
.
As part of this, we should in fact remove setup.py
altogether, since its use has been deprecated. See for instance https://packaging.python.org/en/latest/tutorials/packaging-projects/#configuring-metadata:
Static metadata (setup.cfg) should be preferred. Dynamic metadata (setup.py) should be used only as an escape hatch when absolutely necessary. setup.py used to be required, but can be omitted with newer versions of setuptools and pip.
And https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html
We should make sure that everything still works though. @bouweandela mentioned that possibly pip install -e .
wouldn't work anymore and there were indeed discussions about this (https://discuss.python.org/t/pip-19-1-and-installing-in-editable-mode-with-pyproject-toml/1553/65). I tried it myself, and it doesn't seem to be a problem in my relatively fresh project, but there may be other things. For instance, I see that tox
doesn't immediately work without setup.py
, it mentions that it needs additional configuration when I remove setup.py
:
ERROR: pyproject.toml file found.
To use a PEP 517 build-backend you are required to configure tox to use an isolated_build:
https://tox.readthedocs.io/en/latest/example/package.html
The fix for tox
is to just add isolated_build = True to the tox configuration section in pyproject.toml
.