Should we switch to standards-based package builds? #1486
Replies: 2 comments 3 replies
-
Last time I used |
Beta Was this translation helpful? Give feedback.
-
Hello there, I think it's a good idea to switch to PEP517/518 based builds. Pandas is commenting the build-backend of We can switch to setuptools-scm, matplotlib has made the switch : matplotlib/matplotlib#18971 |
Beta Was this translation helpful? Give feedback.
-
This post is a brain dump of what I've learned about previous, current, and future best practice for python packaging. Nothing here is at all urgent as far as I'm aware, so feel free to bookmark this for a rainy day; I just wanted to lay it out while it's still fresh.
Evolution of the python packaging tools ecosystem
When you install a package via
pip install ...
, part of what's going on under the hood involves a distribution in the form of either ansdist
or abdist_wheel
. We currently generate oursdist
andbdist_wheel
files (.tar.gz
and.whl
files on PyPI) using setuptools, the de facto standard in the python packaging community for many years now.setuptools
, its particular interface (using either setup.py or setup.cfg), and the underlyingdistutils
stdlib all have to maintain backwards compatibility with essentially the entire python ecosystem, making those projects difficult to maintain and extend as the needs of the python packaging community evolve. It's also difficult to switch away fromsetuptools
to some other tool sincepip
only knows how to callsetuptools
.Or at least that's what was claimed by PEP 517, the first in a sequence of Python Enhancement Proposals (PEPs) regarding standardization of a new backend-agnostic build interface for python packaging, where "backend" refers to any tool like
setuptools
that can turn a source tree intosdist
andbdist_wheel
distributions suitable to host on PyPI. I don't necessarily suggest reading them, but the most relevant PEPs to date are PEP 517, PEP 518, and PEP 621. The idea here is that rather than havingpip
run a build tool-specific command likepython setup.py bdist_wheel
to generate a wheel file,pip
would instead look up the desired build tool in some static configuration file and activate that tool via a standardized interface. The configuration file defined in those PEPs ispyproject.toml
.Although
setuptools
used to be really the only reasonable option, the acceptance of those PEPs prompted several alternatives to come about, including in no particular order poetry, flit, enscons, hatch, pdm, and likely others I've not happened to hear about. I think all of these support the interface defined by those three PEPs (excepting poetry, which doesn't yet support PEP 621, see python-poetry/poetry#3332). Anyway the point is thatsetuptools
is no longer the only practical option for building distributions, and in theory it's easy to switch between the alternatives so long as you use the standardizedpyproject.toml
andpython -m build --sdist --wheel
instead of thesetuptools
-specificpython setup.py sdist bdist_wheel
.As of pypa/packaging.python.org#1031, the python packaging guide no longer mentions the
setuptools
-specificsetup.py
andsetup.cfg
files, instead sticking entirely to the standards-based interface and configuration described above. Furthermore,setuptools
itself is also onboard with the new interface andpyproject.toml
configuration (pypa/setuptools#3371 and pypa/setuptools#3214). So it seems likepyproject.toml
is the future, and likely something we'll want or need to adopt at some point.What does this mean for pvlib?
I see three things worth thinking about in light of the above info:
Should we change how we invoke setuptools, i.e. do we stop using
python setup.py sdist bdist_wheel
(keepingsetup.py
itself) and switch topython -m build --sdist --wheel
? I think probably we should, there's little reason not to, plus it sets a good example for any projects that copy pvlib's setup (which is more than a few!). twoaxistracking already does this.Should we change how we configure setuptools, i.e. do we switch from
setup.py
topyproject.toml
? I think there's basically no chance that oursetup.py
is going to stop working anytime soon, so there's no real rush to switch. I do think it's worth looking into switching at some point, but it might not even be possible to switch unless we dump thespa_c
extension stuff (see this forum discussion). Note thatpyproject.toml
is evolving and gaining capabilities over time; if not today, I expect at some point it will be capable of doing what we need.Should we change what backend we're using, i.e. do we switch from
setuptools
to one of the other backends likeflit
? I think until we're confident thatpyproject.toml
can do what we need, there's little point in considering alternative backends. And without a compelling reason to switch to another backend tool, I lean towards "don't fix what ain't broke" here.Beta Was this translation helpful? Give feedback.
All reactions