-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support only re-creating session venv if poetry.lock
has changed
#1063
Comments
For previous art in this area, Tox 4 added support for the equivalent of this for An older Tox plugin |
Upon closer inspection, So for What's convenient is that because the |
poetry.lcok
has changed
poetry.lcok
has changedpoetry.lock
has changed
I'm not sure I understand why you don't just use Is your suggestion that nox-poetry keep track of the |
Yes. Let me try to explain the motivation for this:
In the base Nox configuration, these two goals are at odds. You can set In practice, this happens on projects with large teams. It's not always obvious to know/remember to use The rationale for the speed, we use Nox to provide a simple way to run tools such as black, isort, flake8, mypy, etc. The time for Nox to recreate a venv and install dependencies into it can often times dwarf the time of actually running the tools themselves, leading to a less-than-ideal UX for the developer. With Poetry, we have at least the ability to do what Tox does and smartly recreate the venv only when needed, based on hashing
I can certainly understand/appreciate this! Perhaps a new/different Nox/poetry tool could take this on. |
Nox doesn't skip the install step if you set this option. You need to pass I don't recommend defaulting to venv reuse in the noxfile; it should be an explicit decision. Tox has a different model here AFAIU--they cache by default. Generally, I'd recommend avoiding reuse in CI, as well as locally when you start new work or sync with origin. Then, as you iterate on your work locally, you can choose to speed up things with If you want automation to enforce correct practice across large teams, how about doing the work yourself in the noxfile.py? You could read the current and previous
As nox-poetry author, I have zero issues with this. From the point of view of Nox, it's not ideal though. It would be better if people used the flexibility of noxfile.py before creating more inofficial wrappers. If people really need more flexibility than that, maybe Nox can add official extension points. Also, I'd hope that eventually a PyPA lockfile standard could improve this whole situation, and we'll no longer need tool-specific workarounds. |
nox-poetry
currently by default always recreates the virtual environment on every invocation of the session. This has the advantage of ensuring that the environment is always up to date, but at the cost that environments will be recreated unnecessarily when there are no changes to the locked dependencies.Consider this small example project:
Running a simple lint invocation recreates the environment every time. Even when the wheels are cached on the user's system, the recreation can take significant time and add delay into the developer's workflow:
On a Macbook Pro, it took 16 seconds to recreate this relatively small venv.
If we were to reuse it:
Only 0.9 seconds.
nox-poetry
has an advantage over Nox in that we know that the user is using Poetry. Poetry includes a helpful hash of the entire lockfile and important Poetry-related metadata frompyproject.toml
.If the
content-hash
were read usingtomlkit
(which is already a dependency ofnox-poetry
) and stored with each venv, thennox-poetry
could very quickly check if a virtual environment needed to be recreated or not. This would speed up local development usingnox-poetry
greatly.One open question could be, do we want to also try to handle the case when there are changes to the session itself? For example if different packages were passed to
Session.install()
? Perhaps there would be a simple way to add that with the lockfile hash and then it would be possible to skip the entire install step.This can be demonstrated with this edit to the session:
Avoiding the install entirely speeds up the command even more (because we are skipping the
pip install --contraint...
step which still needs to validate that the venv has all of the needed requirements.The text was updated successfully, but these errors were encountered: