当requirements.txt或setup.py更改时,用tox重新安装virtualenv [英] Reinstall virtualenv with tox when requirements.txt or setup.py changes

查看:79
本文介绍了当requirements.txt或setup.py更改时,用tox重新安装virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我是手动使用看起来像这样的Makefile:

Previously I was manually using a Makefile that looked something like this:

.PHONY: all
all: tests

.PHONY: tests
tests: py_env
    bash -c 'source py_env/bin/activate && py.test tests'

py_env: requirements_dev.txt setup.py
    rm -rf py_env
    virtualenv py_env
    bash -c 'source py_env/bin/activate && pip install -r requirements_dev.txt'

这具有很好的副作用,如果我更改了requirements_dev.txt或setup.py,它将重建我的virtualenv.但是感觉有点笨拙.

This had the nice side-effect that if I changed requirements_dev.txt or setup.py, it would rebuild my virtualenv. But feels a bit clunky.

我想用tox做类似的事情.我知道tox有一个--recreate选项,但是我宁愿在需要时将其称为 .

I'd like to use tox to do a similar thing. I understand tox has a --recreate option, but I'd rather call that only when I need to.

我的新设置如下:

# Makefile
.PHONY: all
all: tests

.PHONY: tests
tests:
    tox

# tox.ini
[tox]
project = my_project
envlist = py26,py27

[testenv]
install_command = pip install --use-wheel {opts} {packages}
deps = -rrequirements_dev.txt
commands =
    py.test {posargs:tests}

理想的解决方案将仅使用tox中的内容,但是可接受的解决方案将涉及Makefile和--recreate标志.

An ideal solution would use just things in tox, however an acceptable solution would involve the Makefile and the --recreate flag.

推荐答案

在此问题中,tox似乎有一个未解决的问题.

There seems to be an open issue in tox for just this problem.

https://github.com/tox-dev/tox/issues/149 (单击并添加您的评论和投票,使作者知道该问题的普遍性)

https://github.com/tox-dev/tox/issues/149 (click and add your comment and vote, making the authors aware about how common the issue is)

我们需要提交补丁或解决它.想到的解决方法:

We'll need to either submit a patch or work around it. Workaround that come to mind:

  1. 直接在tox.ini中列出依赖项.使用您的构建系统来确保tox.ini与requirements.txt保持同步.
  2. 在您的Makefile中添加一条规则,该规则会在require.txt更改时执行tox --recreate命令.
  1. List dependencies directly in the tox.ini. Use your build system to ensure that the tox.ini stays in sync with the requirements.txt.
  2. Add a rule to your Makefile that does a tox --recreate whenever the requirements.txt changes.

解决方法2似乎最简单.

Workaround 2 seems most straightforward.

这篇关于当requirements.txt或setup.py更改时,用tox重新安装virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆