ionelmc / tox-wheel

A Tox plugin that builds and installs wheels instead of sdist. Note that this plugin is obsolte as tox 4.0 already has wheel support.
BSD 2-Clause "Simplified" License
23 stars 10 forks source link

Using tox-wheel as a backdoor cibuildwheel #19

Open dHannasch opened 2 years ago

dHannasch commented 2 years ago

I hope to make a really strange-looking pull request soon, so I want to prepare the field first.

As you know, cibuildwheel uses Docker. In particular, cibuildwheel running inside a Docker container requires dind. This makes cibuildwheel impossible to run without privileged containers.

That's when I started thinking about the possibilities in tox-wheel.

The list of Python versions we build wheels for should obviously always be the same as the list of Python versions we run tests for. We're already storing that list in tox. So why not make that the single source of truth --- why not use tox to build the wheels? tox-wheel is already building the wheels anyway!

And with some minor tweaks to tox-pyenv-install (already made), we can install Python versions on-the-fly if we're missing any, so we don't need cibuildwheel for that either.

This works (for a certain value of "works"), as seen in e.g. https://gitlab.com/library-cookiecutters/python-nameless/-/jobs/2226842902.

creating '/builds/library-cookiecutters/python-nameless/.tox/dist/nameless-0.1.dev50-cp39-cp39-linux_x86_64.whl' and adding 'build/bdist.linux-x86_64/wheel' to it
creating '.tox/dist/nameless-0.1.dev50-cp310-cp310-linux_x86_64.whl' and adding 'build/bdist.linux-x86_64/wheel' to it

(I have no idea why it sometimes prints an absolute path and sometimes prints a relative path, but I don't think it's important.)

So this is all working and building wheels for every Python version we want. The problem, of course, is that tox cleans out the distdir before each env. So at the end of the process, there is always one wheel in the distdir...but only one, whichever wheel was built last. (See e.g. https://gitlab.com/library-cookiecutters/python-nameless/-/jobs/2226871591/artifacts/browse/dist/)

So I want to make it possible to save all the wheels and collect them at the end, analogous to how https://github.com/ionelmc/cookiecutter-pylibrary/blob/master/%7B%7Bcookiecutter.repo_name%7D%7D/tox.ini#L215 reports on code coverage for tests run by other toxenvs. (I'm not yet sure how best to do that, though. Well, if nothing else, tacking on a command to https://github.com/ionelmc/tox-wheel/blob/master/src/tox_wheel/plugin.py#L158 copying the wheel elsewhere would probably work.)