-
Notifications
You must be signed in to change notification settings - Fork 339
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
Recreate Python venv and run pip install less often #912
Recreate Python venv and run pip install less often #912
Conversation
To handle detecting changes in requirements specified via
Looks like some flattening work was done in #889 |
Did the Python tests fail before? 🤔 |
I'm glad there are so many tests to fail! I haven't looked at each and every one, but most seem unrelated, and similar to failings like the recent Rust PR. Dumb question. How can I run a subset of the tests locally? |
The failure https://github.com/cachix/devenv/actions/runs/7312821636/job/19926548496?pr=912 is the issue #909 |
Rather than using a Python lib to do this, we could parse the root requirements file and recursively concatenate all of the files referenced by |
Like this: https://gist.github.com/mcdonc/2653bbfbd33032a12464c8f64c183aff |
I suspect that the poetry test is also failing in the python rewrite PR: https://github.com/cachix/devenv/actions/runs/7312821636/job/19926548605?pr=912#step:8:396
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, the goals of the PR should already have been met:
Don't recreate Python venv unless Nix wrapper has changed.
Using the condition:
if [ "$(${readlink} "$VENV_PATH"/bin/python)" != "$(${readlink} ${package.interpreter}/bin/python)" ]
Don't run pip install -r /nix/store/xxx-requirements.txt unless requirements have changed.
Using the condition:
[ "$(${readlink} "$VENV_PATH"/requirements.txt)" != "$(${readlink} ${if requirements != null then requirements else "$VENV_PATH/requirements.txt"})" ]
In what situation was this not working correctly? Do you have some reproducible steps to see the behaviour failing with the version on main
?
${lib.optionalString cfg.poetry.enable '' | ||
[ -f "${config.env.DEVENV_STATE}/poetry.lock.checksum" ] && rm ${config.env.DEVENV_STATE}/poetry.lock.checksum | ||
''} | ||
echo ${package.interpreter} -m venv "$VENV_PATH" | ||
${package.interpreter} -m venv "$VENV_PATH" | ||
echo ${package.interpreter} -m venv --upgrade-deps "$VENV_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't --upgrade-deps
introduce reproducibility issues? .venv
will have different versions of pip
depending on when you install it. (running it today will install X, running it tomorrow will install Y)
I'm not 100% sure this is a good idea, whether it should be the default and whether it should be behind an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with it not happening. I just wanted to get rid of the irritating "your pip is out of date" warnings :)
This test will always return false currently. See #920 .
There is never a "requirements.txt" within the venv. There might be one within $DEVENV_ROOT, but it's not guaranteed to be named "requirements.txt". We also shouldn't need to recreate the venv when the requirements change, we should just need to rerun pip install of the requirements. The current behavior for either means the venv is recreated on every invocation of We have a few bugs interacting:
|
AFAICT, there is no guarantee that LD_LIBRARY_PATH will exist within the shell? |
With the current way |
We have some longstanding bugs/assumptions and multiple branches interacting, I think, which makes this complex and hard to describe, but I don't think that the python-poetry example should be relying on Assumptions:
Bugs:
It looks like the main branch does indeed set an LD_LIBRARY_PATH in some cases, but I think it's incidental. And on the python-rewrite branch, it might exist within the Python process, but if all goes right, there is at least one scenario where it won't. Rationale: The python-rewrite branch, unlike main, creates a wrapper script (https://github.com/cachix/devenv/blob/python-rewrite/src/modules/languages/python.nix#L13) for the Python defined in You can of course set So I think the right fix is to change the test, because I think it's relying on an artifact of how main is working (which I don't actually understand, but I am pretty confident that the shell, even on main, might not have an LD_LIBRARY_PATH in it unless you set one explcitly). |
@bobvanderlinden maybe you can help me understand the test in |
Hmm, this is probably a recent thing that broke it. It makes sense to fix it, but the current behaviour:
does still seem like it should work. Just that there is a bug in nixpkgs that results in a wrong
Ah sorry, that line is indeed wrong. It should indeed be fixed.
The main branch sets The I'm not entirely sure why these tests aren't running on the python-rewrite branch. I'll try to create a PR that fixes the poetry test for the python-rewrite branch. |
#920 is preventing it from working currently, but that's my understanding as well.
Cool! |
Don't recreate Python venv unless Nix wrapper has changed.
Don't run pip install -r /nix/store/xxx-requirements.txt unless requirements have changed.
This does not take into account use of
-r
in requirements.txt and probably should.This patch is against the python-rewrite branch.
Supersedes #904