John
John

Reputation: 1021

How to specify certain python versions for a given job in tox?

I have a tox config with quite a few jobs, here is a shortened version (Im using poetry):

[tox]
skipsdist = true
envlist =
    format,
    formatting,
    imports,
    flake8,
    pylint,
    docs,
    package
isolated_build = True
whitelist_externals = poetry


; Builds the documentation
[testenv:docs]
deps =
    sphinx
    sphinx_rtd_theme
    toml
commands =
    sphinx-apidoc -o {[project-info]doc_dir} {[project-info]src_dir}
    sphinx-build -b html {[project-info]doc_src_dir} {[project-info]doc_html_output_dir}


; Builds the package
[testenv:package]
deps = poetry
commands =
    poetry install
    poetry build

I would like the docs job to run on any given python interpreter because I don't care about its version but I would like the package job to run on a few specified ones (preferably in specified in one place). How can I do that?

Upvotes: 2

Views: 1522

Answers (1)

Jürgen Gmach
Jürgen Gmach

Reputation: 6121

You can use the basepython setting, see https://tox.wiki/en/3.24.5/example/general.html#basepython-defaults-overriding

; Builds the package
[testenv:package]
basepython = python3.9
deps = poetry
commands =
    poetry install
    poetry build

bonus

Instead of using a comment to describe the tox env, you should use the description setting, see https://tox.wiki/en/3.24.5/config.html#conf-description

[testenv:package]
description = Builds the package
basepython = python3.9
deps = poetry
commands =
    poetry install
    poetry build

When you run tox -lv, you get a helpful overview over the available environments.

$ tox -lv

default environments:
...
docs       -> Builds the documentation
package    -> Builds the package

Upvotes: 2

Related Questions