【问题标题】:temporary use of release candidate python version in tox在 tox 中临时使用发布候选 python 版本
【发布时间】:2016-12-04 16:07:50
【问题描述】:

我正在使用tox 来测试我的python 包。既然 python 2.7.13 有一个候选版本,我如何使用 tox 测试这个版本而不立即替换我当前的 python 2.7 版本以正常使用?

我知道在创建virtualenv 时如何为python 指定路径,然后我可以安装并运行py.test。 Tox 构建了自己的 virtualenv,除了选择 py27、py26、py35 之外,我不知道如何影响安装的 python 版本。

我该如何解决这个问题?

【问题讨论】:

    标签: python-2.7 tox tox-globinterpreter


    【解决方案1】:

    您可以使用 PATH 来影响这一点,方法是在调用 tox 之前扩展您的 PATH(至少在 Linux 上,可能不在 Windows 上)。

    要获得更细粒度的控制并使其在 Windows 上工作(AFAIK 无法像在 Unix/Linux 上那样为单个命令用法设置环境变量),您可以使用 tox 扩展包 tox-globinterpreter (免责声明我是该软件包的作者),您可以使用pip 进行安装。

    该包向tox 添加了一个--scan 选项,该选项写出从py27、py36 等到python 可执行文件的显式映射。

    例如我愿意:

    tox --scan /opt/python/{2,3}.?/bin/python  /opt/python/pypy2/bin/pypy
    

    在我的基于 Linux 的系统上,其中 /opt/python/X.Y 是指向 /opt/python/X.Y.Z 中安装的最新 已发布 Python 版本的链接(或在开发的情况下为最新版本)类似 3.6 的版本),这将作为输出:

    interpreters:
    python2.6 /opt/python/2.6/bin/python
    python2.7 /opt/python/2.7/bin/python
    python3.2 /opt/python/3.2/bin/python
    python3.3 /opt/python/3.3/bin/python
    python3.4 /opt/python/3.4/bin/python
    python3.5 /opt/python/3.5/bin/python
    python3.6 /opt/python/3.6/bin/python
    pypy /opt/python/pypy2/bin/pypy
    

    当我将扫描更改为:

    tox --scan /opt/python/2.6/bin/python /opt/python/2.7.13*/bin/python \
        /opt/python/3.?/bin/python /opt/python/pypy2/bin/pypy
    

    我明白了:

    interpreters:
    python2.6 /opt/python/2.6/bin/python
    python2.7 /opt/python/2.7.13rc1/bin/python
    python3.2 /opt/python/3.2/bin/python
    python3.3 /opt/python/3.3/bin/python
    python3.4 /opt/python/3.4/bin/python
    python3.5 /opt/python/3.5/bin/python
    python3.6 /opt/python/3.6/bin/python
    pypy /opt/python/pypy2/bin/pypy
    

    tox -e py27 将使用 2.7.13 候选版本。如果来回切换,你可以保存配置文件(~/.config/tox 或%APPDATA%\tox),但重新运行扫描非常快,所以我会为此制作一个 shell 脚本/别名/批处理文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-12
      • 2021-10-30
      相关资源
      最近更新 更多