Zum Inhalt der Seite gehen


Last week I had to upgrade my tootgroup.py tool to fix a deprecated dependency. While I was at it, testing installs etc. I was finally nudged enough by pip to take the plunge and switch the build setup from directly using setup.py to pyproject.toml.

Here a few thoughts for those who are interested or might be in a similar situation

pyproject.toml has been the recommended way for building python projects for a few years now. Unfortunately the documentation about it was abysmal in the beginning. This was the main reason why I did not tackle the switch until now. Luckily the situation has changed for the better. Everything one needs is documented and can be found - somewhere... kind of distributed... But I was able to find everything I needed in the end.

The TLDR is, if you have been using setuptools until now, you just can continue using it with your existing setup.py and a minimal pyproject.toml with only the [build-system] part. This is true as long as your project is sufficiently simple and might help to ease some anxiety.

The longer story - If you want, you can completely replace setup.py with a more involved pyproject.toml. Even if you continue to use setuptools as a build backend (which you probably will). This is what I did in the end and here is a guide as starting point for further research.

Do not believe howtos that also recommend a setup.cfg file. This works but is no longer the "way to go". In fact, try to stay away from all of the numerous old howtos. This was the hardest thing form me - sieving out the relevant info from all the old blog posts and the like.

So how does it look like - Have a look and compare yourself.

The old setup.py: https://github.com/oe4dns/tootgroup.py/blob/v1.4.2/setup.py

And the new pyroject.toml that completely replaces it: https://github.com/oe4dns/tootgroup.py/blob/v1.4.3/pyproject.toml

The only thing that really differs is how the version string is set dynamicly. Which is in fact easier now than it was before.

In the end it was easier than expected and I am happy to finally having caught up to modern python standards. Instead of "python setup.py sdist bdist_wheel" I now build with "python -m build" and thats it.

#python #buildsystem #setuptools #pyproject.toml