-
-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtualenv is not recreated when deps change if '-r' is used #149
Comments
Original comment by wbyoung @wmyll6 thanks for the plugin. Hopefully some of that work can make its way into the core! |
Original comment by @signalpillar Hello guys, I've created an experimental project that supports venv recreation on requirements file update. Implemented using plugin system that was added recently to the tox. |
Original comment by hexadite-maxk This is rather philosophical question: if we want tox to be smart or stupid. |
Original comment by @merwok This also happens if dependencies in setup.py (install_requires) change. |
Original comment by @hpk42 Within tox-1.9.1 (superseded quickly by 1.9.2) we had some code that parsed requirement files but it was buggy and caused problems. I am all for adding proper support for dealing with requirement files in deps. I think that tox will need to support pip==1.5.6 at least if not older versions. |
Original comment by @hpk42 If somebody can submit a PR helping with working better with "-r" lines, please do. Note that i just released tox-1.9.1 which contains some code in relation to "--force-deps" which parses requirements. |
Original comment by @bukzor That's only slightly better. Requirement files can and do contain '-r To the dependency concern: tox already has a hard dependency on virtualenv, --phone is hard. |
Original comment by mhirota What about recognizing the special case of |
Original comment by @hashar A way to reproduce:
Then add a new requirement and rerun tox:
|
Original comment by @asottile For what it's worth, here's a hacky workaround with a Makefile: http://stackoverflow.com/questions/23032580/reinstall-virtualenv-with-tox-when-requirements-txt-or-setup-py-changes/23039826#23039826 |
Any chance of porting |
@dimaqq it already is on github - @signalpillar is the maintainer/owner |
Are there opinions about how we should deal with this? I would tend to close this and recommend using tox-battery for now. |
I'll have to disagree - this is an issue I hear from various people, and it's quite unexpected. I view it as "tox does caching without invalidating the cache correctly" essentially. The core does caching, so I think it really should do this correctly. |
o.k. - I stand corrected then :) |
we once had better support for requirements parsing but we had to revert it ... i admit i never extensively used -r requyirements.txt myself and the docs still mark that feature as experimental http://tox.readthedocs.io/en/latest/example/basic.html?highlight=requirements#depending-on-requirements-txt -- someone needs to step up to go for it more properly ... meanwhile recommending to manually use "tox -r" for recreating an env is a kludge to get around tox's ignorance. |
FWIW, in my latest project I avoid the issue by using pip-tools. I never recreate virtualenvs, but dependencies (in one or more requirements files, e.g. run.txt and test.txt) are always synchronized, so I get fast failures before commit and CI if I forget to update requirements. |
@merwok that sounds interesting, but I have no idea what you are talking about - could you link to some documentation/blog/howto/whatever with more details about this approach? Thanks! |
@obestwalter one approach (that we're using internally, and will have a better solution for once 2.7.0 ships with my plugin changes :D) is to use https://github.com/Yelp/venv-update -- pip-faster has a |
@obestwalter pip-tools can be used to keep a virtualenv exactly in sync with the requirements. It's really a great idea to use it in tox. Should have thought of that myself. |
It is indeed https://github.com/jazzband/pip-tools tox.ini: [testenv]
deps =
pip-tools == 1.8.1rc3
commands =
pip-sync requirements.txt requirements-test.txt
pyflakes project
pytest {posargs} pip-sync makes sure new dependencies or updated versions are installed in the virtualenv and removes old dependencies. I don’t duplicate dependencies in tox.ini, I never have to recreate the testenvs, my co-workers never have failures because requirements.txt changed. My deployment also uses pip-sync. Article from the original developer of pip-tools: http://nvie.com/posts/better-package-management/ pip-tools very recently gained the ability to generate requirements.txt with pinned versions from dependencies in setup.py, so you can have a lib with loose requirements in setup.py and exact pinned versions in requirements-test.txt for your tox testing. |
Very nice. Thanks for the info. I had build my self built version (something similar to what pip-tools does) for our team projects, that I might be able to throw out now :) To get back to the original issue: in the light of the fact that this problem is better solved by a tool that can be used by tox maybe it would be better to deprecate the -r option and throw it out in the next major release? I don't use this option either as I had my own solution, but will definitely try pip-tools for this now. |
I'm very glad to see this discussion coming back to life. My 2c/experience:
|
@asottile can you detail? thanks! |
venv-update aims to solve nearly the same thing as pip-tools but does so in a different implementation. Note that while confusing, venv-update and pip-faster are one-and-the-same (there has been some significant confusion in development as we've renamed the project back and forth at least once now!). The usage is almost identical to pip-tools above:
The plugin I'm writing works similarly to this ^ Internally, we suggest a dependencyless approach which involves vendoring a copy of venv-update and using it as follows:
venv-update currently supports cpython 2.6, 2.7, 3.5, 3.6, pypy -- it is known to work in 3.3+ (and may very well work for 3.2 and below as well as pypy3.2 but we've stopped testing against those due to the pypa group dropping support). It is likely to also work for modern pypy3 (targeting 3.5.x). No attempt to verify its behaviour has been made against ironpython / jython / etc. There is one outstanding kinda awful bug that is similarly shared by pip itself. pip-tools avoids this by uninstall-then-install whereas venv-update does install-then-uninstall -- it's not clear if there's an easy fix for this (it's kind of a rare case and we haven't invested any time into investigating / fixing). |
I don’t know what «one-step build» refers to. In my usage, calling pip-compile to add a new dependency or upgrade existing deps is something I do during development when I choose to; the install step in tox testenvs or before starting the app is only pip-sync. |
Yes, and it's planned for tox 4 🤔 |
That's actually a brilliant idea. It would also make sense to order requirements before hashing, so change in order don't result in an environment recreation. |
This approach has been discussed before (probably multiple times by now?) in this thread. The main problem is that requirement files can include others via |
Order is significant in requirements files (for now at least — Pip's new resolver may change that). |
Tox does not detect changes in requirements, and will fail with missing imports. [example](https://saml.buildvm.openshift.eng.bos.redhat.com:8888/job/art-tools/job/elliott/job/master/6/console) [tox bug](tox-dev/tox#149) This PR looks at the files that have changed in the last 5 commits, and if one of the files that might contain requirements have changed, will add the argument `--recreate` to the `tox` invocation. The magical number 5 was chosen, as it is conceivable that there are multiple commits locally which contain the change, and the change in dependencies is not detected. Alternative approaches are: - install a tox plugin - always recreate in Jenkins
Tox does not detect changes in requirements, and will fail with missing imports. [example](https://saml.buildvm.openshift.eng.bos.redhat.com:8888/job/art-tools/job/elliott/job/master/6/console) [tox bug](tox-dev/tox#149) This PR looks at the files that have changed in the last 5 commits, and if one of the files that might contain requirements have changed, will add the argument `--recreate` to the `tox` invocation. The magical number 5 was chosen, as it is conceivable that there are multiple commits locally which contain the change, and the change in dependencies is not detected. Alternative approaches are: - install a tox plugin - always recreate in Jenkins
Using "-r requirements.txt" in tox is so common that I'm suprised this issue has remained unresolved for >4 years instead of being solved by a hotfix. When is tox 4 planned to be released? |
It's a fairly complicated issue, it's more like adding a major feature than hotfix. We have an alpha version of it https://pypi.org/project/tox/4.0.0a2/, a first public release expected in a few months. |
Also use pip-sync, to avoid having to use `tox -r` when we change or upgrade our requirements, see: tox-dev/tox#149 Which is good for CI stability: if black passes today, it'll pass tomorrow.
Hi @merwok, as a user of pip-compile, I was willing to try this today, slighly modified version of you comment from 2017:
Issue is: pip-sync uninstalls the project being tested :D Do you still use this "trick"? If so have you found a nice and clean way to workaround this? |
Hi @JulienPalard, I haven't tried with tox specifically, but I usually have this in my
(Replacing This tells HTH |
Two options:
|
Thanks @merwok and @nicoddemus for sharing! |
I'm closing this as this has now been implemented in the alpha branch of rewrite. We can open more specific issue tickets on the implementation separately. |
@gaborbernat How about adding a |
You got it 👍🏻 |
The operations-puppet Docker image holds Python dependencies by running `tox --notest` on build. However when a change is made to one of the requirements files, tox does not notice any difference and fail to update/refresh the requirements. The root cause is tox-dev/tox#149 which apparently got addressed by the tox version 4 rewrite. Install tox from source so we can get a more recent version than the one provided by Debian. I have picked 4.4.10 which is the latest at the time of this change. Bug: T345152 Change-Id: Icdddcb3e81727c04ccee16187f471fdf62f6199f
Applies official workaround indicated by tox core maintainers for avoiding tox-dev/tox#149 which allowed tox to run with without updating dependencies declared in external files. Depends-On: https://review.openstack.org/#/c/617145/ Change-Id: I358b80d183a2667a04cfaac2054e101a9d7454ed
In my tox.ini, I have the following deps:
Normally, when deps change, the virtualenv is recreated by tox.
However, when the contents of requirements.txt change, tox does not notice this and the environment is reused.
A workaround would be to list the deps directly in tox.ini, but that would require duplicating the contents of the existing requirements.txt that is used by other tools.
The text was updated successfully, but these errors were encountered: