'Using tox and pyproject.toml

I am trying to switch a project from using setup.py to PEP518. I have written the following minimal pyproject.toml:

[build-system]
requires = ["cython", "setuptools", "wheel", "oldest-supported-numpy"]
build-backend = "setuptools.build_meta"

I need some custom installation logic relying on setup.py, so I cannot currently switch to a purely declarative setting.

Notably, my setup.py contains an import numpy which I use to add numpy.get_include() to the includes of an extension. I can build the sdist / wheel using python -m build, which works as intended (providing a build environment by installing the dependencies before calling into setup.py)

I also have a test suite which I run using tox. However, when I run tox in my project I see the following error:

GLOB sdist-make: /project/setup.py
ERROR: invocation failed (exit code 1), logfile: /project/.tox/log/GLOB-0.log
...
File "/project/setup.py", ...
ModuleNotFoundError: No module named 'numpy'

So, per default tox does not install the build dependencies before building the sdist to be used for testing later, causing everything to fail.

Therefore, as suggested in the tox example, I added

[tox]
isolated_build = True

[testenv]
commands = pytest

to the top of tox.ini, which should enable the isolated build. However, when I then execute tox now, all I get is

___ summary ___
  congratulations :)

so nothing is actually built / tested (as opposed to a non-isolated build with numpy installed). Is this the expected behavior? How can I actually build and run tests in an isolated environment?



Solution 1:[1]

OK, so as it turns out, isolated builds require an envlist like this to work properly (as opposed to the ordinary one which defaults to using the current python environment):

[tox]
isolated_build = True
envlist = py310

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hfhc2