uv python install and uninstall now account for the UV_PYTHON env var#10222
uv python install and uninstall now account for the UV_PYTHON env var#10222Choudhry18 wants to merge 14 commits intoastral-sh:tracking/060from
Conversation
…iable and added a test for that
|
Hey @Choudhry18 I fixed some merge conflicts and expanded the test cases. I have one comment; otherwise this looks good to me! |
crates/uv/tests/it/python_install.rs
Outdated
| // We should ignore `UV_PYTHON` here | ||
| uv_snapshot!(context.filters(), context.python_uninstall().arg("--all").env(EnvVars::UV_PYTHON, "3.11"), @r###" | ||
| success: false | ||
| exit_code: 2 | ||
| ----- stdout ----- | ||
|
|
||
| ----- stderr ----- | ||
| error: the argument '--all' cannot be used with '<TARGETS>...' | ||
|
|
||
| Usage: uv python uninstall --all --install-dir <INSTALL_DIR> <TARGETS>... | ||
|
|
||
| For more information, try '--help'. | ||
| "###); |
There was a problem hiding this comment.
This test failure is problematic — this needs to work still.
There was a problem hiding this comment.
I see you mentioned this at
As the --all arg conflicts with target it also conflicts UV_PYTHON env variable
We might need to implement this differently to work around this. Perhaps --all should just override the targets?
There was a problem hiding this comment.
I do agree that -all should override targets as I don't see a case where a user would add -all argument without intending to delete all the version. So all should override targets set through argument or environment. Do we need to give the user a warning (I personally don't think it's needed) like:
Setting targets with -all is redundant and just result in all managed python versions being uninstalled
There was a problem hiding this comment.
Yeah I don't think a warning is needed, it's a weird case but it seems fine to just ignore the target silently unless someone reports a confusing interaction.
There was a problem hiding this comment.
Ah are you suggesting that we should remove the conflict entirely and let someone do uv python uninstall foo --all? I think that could be too confusing :/
There was a problem hiding this comment.
yes that is what I had in mind that if --all is set target shouldn't matter . I do agree invalid targets with --all not giving an error can be a bit confusing. Currently uv python uninstall foo -all doesn't really tell the user that their target is invalid it just tells them of the conflict of target with --all
So what I understand is you suggest that --all should override target but if it target is invalid it should throw an error
There was a problem hiding this comment.
Oh sorry I mean uv python uninstall 3.11 --all would be confusing too — just used foo as a silly example.
There was a problem hiding this comment.
oh so you suggest the target set as an argument should behave differently in case of use with --all (throw an error citing a conflict) vs target set through the env variable should be ignored silently. Apologies that took me a minute to understand :/
That makes sense for usage here the only concern I have is are there any other env variable that behave like this in uv. Most of the env variable I have seen they are sort of a replacement for just having to type to argument again and again and behave exactly the same as the cli argument. So this behaving differently might be not be very idiomatic. I also might just be overthinking this one.
There was a problem hiding this comment.
oh so you suggest the target set as an argument should behave differently in case of use with --all (throw an error citing a conflict) vs target set through the env variable should be ignored silently. Apologies that took me a minute to understand :/
Yeah, that's the suggestion. No problem on the confusion.
Most of the env variable I have seen they are sort of a replacement for just having to type to argument again and again and behave exactly the same as the cli argument. So this behaving differently might be not be very idiomatic. I also might just be overthinking this one.
I think it's okay in this case. Though I'm not sure of the implications implementation-wise.
There was a problem hiding this comment.
I couldn't find a suitable way to implement it using clap's derive API. My workaround was writing a custom validation check that is ran after the parsing and before the uninstall Settings are resolved. The implementation does get a bit ugly in order to replicate the format of the error message without using the derive API
… through custom validation that is called before resolving settings
|
I found the early-validation a bit awkward (as you noted) and moved it into the implementation. I'm finding myself a little hesitant about changing the |
|
Exploring that in #11487 |
Unlike #10222, this does not respect `UV_PYTHON` in `uv python uninstall` (continuing to require an explicit target there) which I think is simpler and matches our `.python-version` file behavior. --------- Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Aria Desires <[email protected]>
Unlike #10222, this does not respect `UV_PYTHON` in `uv python uninstall` (continuing to require an explicit target there) which I think is simpler and matches our `.python-version` file behavior. --------- Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Aria Desires <[email protected]>
Unlike #10222, this does not respect `UV_PYTHON` in `uv python uninstall` (continuing to require an explicit target there) which I think is simpler and matches our `.python-version` file behavior. --------- Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Aria Desires <[email protected]>
Unlike astral-sh#10222, this does not respect `UV_PYTHON` in `uv python uninstall` (continuing to require an explicit target there) which I think is simpler and matches our `.python-version` file behavior. --------- Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Choudhry Abdullah <[email protected]> Co-authored-by: Aria Desires <[email protected]>
Summary
Checks UV_PYTHON for version when
uv python installoruv python uninstallranTest Plan
I added new snapshot tests:
uv/tests/it/python_install::python_install_with_uv_python_env that sets UV_PYTHON to and tests if that version is installed and not the latest. UV_PYTHON=3.12 uv python install would install 3.12 and not the latest version
uv/tests/it/python_install::python_install_with_uv_python_env_and_arg that sets the env variable and the target and tests if the target takes precedence. UV_PYTHON=3.12 uv python install 3.8 would install python 3.8
Requirement Concern
The order of precedence on the python install command is : target specified through cli -> environment var UV_PYTHON -> .python-versions if none other specified.
The order of precedence on the python uninstall command is: target specified through cli (required unless UV_PYTHON set) -> environment var UV_PYTHON (required unless target provided in cli). As the --all arg conflicts with target it also conflicts UV_PYTHON env variable
closes #10128