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.
Uh oh!
There was an error while loading. Please reload this page.
-
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 ansdistor abdist_wheel. We currently generate oursdistandbdist_wheelfiles (.tar.gzand.whlfiles 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 underlyingdistutilsstdlib 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 fromsetuptoolsto some other tool sincepiponly 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
setuptoolsthat can turn a source tree intosdistandbdist_wheeldistributions 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 havingpiprun a build tool-specific command likepython setup.py bdist_wheelto generate a wheel file,pipwould 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
setuptoolsused 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 thatsetuptoolsis 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.tomlandpython -m build --sdist --wheelinstead 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.pyandsetup.cfgfiles, instead sticking entirely to the standards-based interface and configuration described above. Furthermore,setuptoolsitself is also onboard with the new interface andpyproject.tomlconfiguration (pypa/setuptools#3371 and pypa/setuptools#3214). So it seems likepyproject.tomlis 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.pyitself) 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.pytopyproject.toml? I think there's basically no chance that oursetup.pyis 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_cextension stuff (see this forum discussion). Note thatpyproject.tomlis 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
setuptoolsto one of the other backends likeflit? I think until we're confident thatpyproject.tomlcan 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