-
Notifications
You must be signed in to change notification settings - Fork 793
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
uv add
/uv sync
/... do not respect the active virtualenv, should they?
#6612
Comments
I'm a bit of a configuration junkie, so my immediate opinion is "yes—under a configuration option". If a configuration option is deemed too complex for this, I think it'd still be nice to make it the default behavior to support the "external venv" workflow, though a message should be printed if the active venv seems to be outside the current project. If the current project has a venv, but the active venv is different, I'm not sure which should be used by uv; maybe it should just result in an error. |
At the very least, I think we should warn if there's an active virtual environment that isn't the target. We're very hesitant to sync to active virtual environments. I'll be considering this as we hear more use cases. |
This is confusing to me, If I do:
Shouldnt the |
Yeah, |
here's our use case that is tripping me up. We have a docker image that gets built and we use an activated venv in there. During development/testing, this docker image is also used and we mount the local development directory I dont want the dev/test to use the local For now I have worked around it by setting up the build to use a link from |
Yep! We agree the Docker volume mount is a big problem and we are working on designing a recommended solution. Does adding |
|
Yep, just struggled with that myself. Have you tried docker compose watch? Is that an option for you? |
Also, have you tried |
ah, watch is something is new, and did not know about. I'll try both options. |
Thanks! Let me know if you have any problems — I'm writing some examples up with those. |
Hi, I was going to add a similar issue here. I think more than respecting current active virtualenv, they should also respect the I would prefer if we could select the virtualenv folder in uv.toml or pyproject.toml For historical reasons, on some projects the name of the env folder is relevant (and .venv is also an arbitrary name) |
that one did not work for me for one of the cases I am trying, because then I cant do the
|
Can you share a concrete example? I'm not quite following and am happy to debug. |
assuming
Then if I try the
which if I am understanding your suggestion correctly, it will override
|
Sorry I think I'll need to see a complete minimal example. Perhaps you could derive a small multi-stage image as you describe from this (work in progress) example: https://github.com/astral-sh/uv-docker-example |
ok, let me adapt that example in a fork, and push it in a few |
ok, I see the bit that I was missing. I need to copy the |
This would be very helpful for us, too. Our use case is that we run tox in our pipeline and the first step is to verify and install the requirements for the unit tests. So basically we would like to do |
I kind of understand (though not exactly fully). I think I would be pretty happy if the sync/add/... commands accepted e.g. (I suppose |
Can you explain the reasoning behind this? I thought most users activate a virtual environment to ensure they're not modifying anything globally. similar to @akx I keep my virtual environments outside of the repo to save space. Then have an alias to activate whichever environment I need or want to test. It would be nice to have an |
It seems kind of wild to not respect VIRTUAL_ENV, for any command honestly. I'm not sure I can imagine a drawback. in the happy path, no one is setting it, or otherwise activating the virtualenv. but in every other case, it's the path of least surprise to me. I frequently use quick swapping of virutalenvs under different names to fast test across multiple versions of python. I personally do so with my own tool (currently, would love to stop using it) Somewhat tangentially related, I submitted #1495 a while back basically to facilitate this workflow. Where ideally i wouldn't even necessarily be activating any of the venvs, if i could be doing something like |
Just a brief drive-by comment: this is something we've considered but cut from scope for last week's release :) |
👋 Big +1 for the principle of least surprise when it comes to not just using the active I'm sympathetic towards not wanting to try and heal a broken virtualenv (if indeed this is the motivation), and there are at least a few places in the documentation where I've seen "unexpected behavior" if uv ends up executing a different python binary than the one living in the virtualenv for one reason or another. As a workaround, I've discovered that Considering venvs are already roughly ephemeral, even if (New user here, I'd like to take the opportunity to express my gratitude both to the team as well as all contributors for the fantastic tool 🙂) |
I'm really interested in how this effects the tox/nox workflow since, prior to this release I have been using nox for most of my projects/script management. Do we have any suggestions on how to handle similar workflows with the project/workspace interface? |
I would prefer it if e.g. It was the most surprising thing I found when starting to use It also is a surprising difference from |
I don't know if anyone got my suggestion above, but it would be great if there was a config in pyproject.toml to refer to the virtual env path besides the VIRTUAL_ENV variable (of course an active env would take priority).
or
I'm very eager to use this new add/sync interface! Thank you guys for such cool project |
If that was going to be a feature, |
Maybe you are thinking about libraries, but it is common for a project meant to run directly to have several strong opinions on where things are located. According to the latest 0.4.0 release notes, it seems to be a goal of uv to cater to theses projects. Direct quotes from the maintainer:
|
i mean, it's ultimately up to them, but it seems weird to me for the project (versus myself or the tool) to have control over where my venv goes, regardless of the usecase. it totally makes sense for uv to have strong opinions or for the user. but i just really dont see a reason for the project itself to care (particularly with a tool like |
Take a look at #6834 and let me know if it is sufficient for you. Please remember to be considerate. |
I certainly dont think there's anything wrong with uv also having it's own env var that takes precedence over VIRTUAL_ENV, whether or not you respected it, the PR still seems like a net improvement in the mean time. But in my mind, all of the reasons you state in the PR for being reasons against supporting
So if someone's going to use this env var for any of the local-development usecases (docker/ci both seem addressed by the PR either way) either forces one to set both or prefix everything with one runs interactively with For my own purposes of fast swapping between python versions interactively, which is how i landed here in the first place, this env var is inconvenient as a solution relative to the standard env var for the reasons stated above, but i suppose perhaps #1495 will have to be the solution. |
I have a use-case similar to @DanCardin's. Basically, I don't use tox/nox, and instead prepare one venv per Python version I support. Then I install deps in each one of them, and use scripts to run the same commands in all of them, one after the other. # Create default .venv, as well as .venvs/3.8, .venvs/3.9, etc., and install deps in each
make setup
# Run tests in all venvs
make multirun duty test # shortcut: make test
# Serve docs from default env
make run duty docs # shortcut: make docs
# Install something in all venvs, including default env
make allrun uv pip install ... Currently my Ideally, I'd love that |
It's very confusing to me why
The following should just work. I would expect this to create a new virtualenv in
At the very lest the docs should be updated to explain what commands respect the In the Docker context, I don't really want to be forced into creating my virtualenv in |
Yes, that would be sufficient for our use case. Thanks a lot for your work! |
I also agree, that would solve my issues as well! Thank you for the quick resolution here! |
@epicserve that is discussed a bit in the summary of #6834 — we can add more documentation around this though. Thanks for looking at the pull request everyone. |
Related to #1495, #5229, but not exactly the same IMO.
Like #1495, I prefer to have my virtualenvs located centrally instead of in project directories. I have a Fish shell function called
v <NAME>
that activates a virtualenv~/envs/<NAME>
if available and cds to the related project directory~/build/<NAME>
if available.I wanted to try out
uv add
anduv sync
and was initially somewhat confused when they didn't seem to do anything, only to realize that they currently always work on the~/.venv
virtualenv, and don't even stop to consider a currently active virtualenv to work on.There's apparently a workaround to symlink
.venv
to the centrally-located venv, but that also seems a bit messy too.I think it should be at least an (envvar or config-file) option to have the "project venv" tools (
run
,add
,remove
,sync
, etc.) consider the currently active virtualenv, if any.Pretty minimal Docker container repro:
The text was updated successfully, but these errors were encountered: