Erik Thiede Erik Thiede - 5 months ago 48
Python Question

Understanding Non-Default Python Configuration in tox.ini

I'm trying to learn more about the details of configuring tox.ini files. In one of the files for the Jupyter project and in this demo project, rather than using the default python environments, they define new environments in the command:

basepython =
py27: {env:TOXPYTHON:python2.7}
py33: {env:TOXPYTHON:python3.3}

What is the advantage to this? Also, what does the command with env:TOXPYTHON command accomplish? I couldn't find it in the tox documentation.

Answer Source

The main concepts to understand here are:

  1. Generating environments, conditional settings

if the environment that is run contains one of the factors listed before the colon than this is valid.

  1. Environment variable substitutions with default values

The elements in the curly braces get replaced depending on the state of environment variables set in the shell tox is run in.

Putting it together the meaning of your snippet is:

py27: {env:TOXPYTHON:python2.7}

If the factor py27 is part of the tox environment name (e.g "py27-unittests") use as basepython either the value if the environment variable TOXPYTHON or the literal "python2.7" if the environment variable is not set.

Same principle is valid for environments contataining the factor py33.

The advantage is that you as a developer working on this can set the TOXPYTHON environment variable according to your needs in case python2.7 or python3.3 are not in your path. This is (I guess) a result of tox having some weak spots regarding interpreter discovery on the different Osses and distributions. See:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download