简体   繁体   English

在tox中临时使用release candidate python版本

[英]temporary use of release candidate python version in tox

I am using tox to test my python packages. 我正在使用tox来测试我的python包。 Now that python 2.7.13 has a release candidate, how do I test against this version using tox without immediately replacing my current python 2.7 version for normal use? 现在python 2.7.13有一个候选版本,如何使用tox测试这个版本而不立即替换我当前的python 2.7版本正常使用?

I know how to specify a path for python when creating a virtualenv and then I can install and run py.test . 我知道如何在创建virtualenv时为python指定路径,然后我可以安装并运行py.test Tox builds its own virtualenv and I don't know how to influence the python version installed beyond selecting py27 , py26 , py35 . Tox构建自己的virtualenv,我不知道如何影响安装的python版本,除了选择py27py26py35

How can I solve this? 我怎么解决这个问题?

You can influence this using the PATH, by extending your PATH before calling tox (at least on Linux, probably not on Windows). 您可以使用PATH对此进行影响,方法是在调用tox之前扩展PATH(至少在Linux上,可能不在Windows上)。

To get some more fine grained control and to get that to work on Windows (where AFAIK you cannot set an environment variable for a single command usage like on Unix/Linux), you can use the tox extension package tox-globinterpreter (disclaimer I am the author of that package) which you can install with pip . 要获得更精细的控制并使其在Windows上运行(其中AFAIK不能为Unix / Linux上的单个命令使用设置环境变量),您可以使用tox扩展包tox-globinterpreter (免责声明我是你可以用pip安装的那个软件包的作者。

The package adds a --scan option to tox which writes out an explicit mapping from py27 , py36 , etc to a python executable. 该软件包为tox添加了一个--scan选项,它将py27py36等的显式映射写入python可执行文件。

Eg I do: 我这样做:

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

on my Linux based system, where /opt/python/XY is a link to the latest released Python version as installed in /opt/python/XYZ (or the latest version in case of development version like 3.6), this gives as output: 在我的基于Linux的系统上,其中/ opt / python / XY是安装在/ opt / python / XYZ中的最新发布的 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

When I change the scan to: 当我将扫描更改为:

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

I get: 我明白了:

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

And tox -e py27 will be using the 2.7.13 release candidate. 并且tox -e py27将使用2.7.13发布候选版本。 You can save the configuration file (in ~/.config/tox or %APPDATA%\\tox ) if switching back and forth, but rerunning the scan is pretty fast, so I would make a shell script/alias/batch file for that. 如果来回切换,您可以保存配置文件(在~/.config/tox%APPDATA%\\tox ),但重新运行扫描非常快,所以我会为此创建一个shell脚本/别名/批处理文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM