tox always uses python 2.7 to build envs. can't work on projects with python3 code in setup.py

Issue #334 on hold
Conrad NA created an issue

I've added the following to my setup.py:

import sys
with open("what.version.is.this.txt", "w") as f:
    f.write(str(sys.version_info) + "\n")

my tox file looks like this:

[tox]
basepython=python3
envlist = py35

[testenv]
basepython=python3
deps =

[testenv:py35]
basepython=python3
skip_install = true
skipsdist = true
deps =
    mypy-lang
commands = mypy --py2 zulip

and the following gets written out:

$ cat what.version.is.this.txt
sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)

This is a problem because the project I'm trying to add tox to uses a module found only in python3.

tox
GLOB sdist-make: /Users/cdean/dev/foss/python/zulip/api/setup.py
ERROR: invocation failed (exit code 1), logfile: /Users/cdean/dev/foss/python/zulip/api/.tox/log/tox-0.log
ERROR: actionid: tox
msg: packaging
cmdargs: ['/usr/local/opt/python/bin/python2.7', local('/Users/cdean/dev/foss/python/zulip/api/setup.py'), 'sdist', '--formats=zip', '--dist-dir', local('/Users/cdean/dev/foss/python/zulip/api/.tox/dist')]
env: None

Traceback (most recent call last):
  File "setup.py", line 9, in <module>
    from typing import Any, Generator, List, Tuple
ImportError: No module named typing

ERROR: FAIL could not package project - v = InvocationError('/usr/local/opt/python/bin/python2.7 /Users/cdean/dev/foss/python/zulip/api/setup.py sdist --formats=zip --dist-dir /Users/cdean/dev/foss/python/zulip/api/.tox/dist (see /Users/cdean/dev/foss/python/zulip/api/.tox/log/tox-0.log)', 1)

What am I doing wrong here?

Comments (4)

  1. Sebastian Noack

    Apparently, tox builds the package (i.e. runs setup.py sdist) once using the same interpreter that runs tox itself. Then it installs the package inside each virtualenv along the dependencies, and runs any command using the corresponding Python interpreter. FWIW, I agree this behavior isn't great, not only in your case, but it generally means that setup.py is never tested with different Python versions. As a workaround, you can call setup.py explicitly rather than having tox handle the packaging:

    [tox]
    envlist = py35
    skipsdist = True
    
    [testenv]
    commands =
        python setup.py install
        ...
    

    Another workaround, in your case, would be to install and run tox itself with Python 3.

  2. Log in to comment