Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

python - Is there a way to ask tox to run environments matching a name or by group?

I have a tox.ini with several envs, like this example:

[tox]
envlist =
    py37,
    py38,
    py39,
    lint-{foo,bar,baz}
...

For several of my users, only a subset of these is useful at a time, usually all the py3 ones or all the lint- ones.

Is there a syntax such that instead of tox -e py37,py38,py39, one can say "run all envs (a subset of what tox finds via tox -a) matching py3"?

Alternatively, is there a way to group the envs so that one can say "run the test envs" or "run the cleanup envs" without losing the ability to call tox to run them all?

I can write a separate script to handle this, but I'm searching for a built-in way to match.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The closest to a built-in way to filter tox environments by name is the TOX_SKIP_ENV environment variable, which tox uses as a pattern for re.match (see source) with each environment name, skipping those that match.

So, for example, to only run the lint- prefixed environments, one could:

env TOX_SKIP_ENV='^(?!lint-)' tox

Or, to skip all envs with py or bar anywhere in the name...

env TOX_SKIP_ENV='.*?(py|bar)' tox

There is a (currently unmaintained) tox plugin, tox-tags, aiming to provide roughly the tagging/grouping functionality I was thinking of.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...