从 tox 命令捕获版本

Capture just version from tox commands

我的 tox.ini 中有以下内容:

[tox]
skipsdist = true
envlist = py27, py36, lint

[testenv]
whitelist_externals=flake8
commands =
    version: python setup.py --version

当我运行

tox -e version

我得到以下输出:

tox -e version 2>version
version runtests: PYTHONHASHSEED='3264081464'
version runtests: commands[0] | python setup.py --version
0.2.0
__________________________________________________________________________________________________________________________________________________________ summary ___________________________________________________________________________________________________________________________________________________________
  version: commands succeeded
  congratulations :)

我只需要从 tox -e version[=24 捕获版本 (0.2.0) =] 输出,最 elegant/pythonic 的做法是什么?无论如何我也可以让 tox 只将输出输出到命令而不是其余的输出吗?

tox 命令中包含 -qq 应该会将输出减少到 0.2.0.

将版本保存到文件中。在 tox.ini:

[testenv]
whitelist_externals = /bin/sh
commands =
    version: /bin/sh -c "python setup.py --version >version"

在shell中:

tox -e version
cat version
rm version