Skip to content

Comments

uv python install and uninstall now account for the UV_PYTHON env var#10222

Closed
Choudhry18 wants to merge 14 commits intoastral-sh:tracking/060from
Choudhry18:env_var_python_install
Closed

uv python install and uninstall now account for the UV_PYTHON env var#10222
Choudhry18 wants to merge 14 commits intoastral-sh:tracking/060from
Choudhry18:env_var_python_install

Conversation

@Choudhry18
Copy link
Contributor

@Choudhry18 Choudhry18 commented Dec 29, 2024

Summary

Checks UV_PYTHON for version when uv python install or uv python uninstall ran

Test 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

@zanieb zanieb self-assigned this Dec 30, 2024
@Choudhry18 Choudhry18 requested a review from samypr100 January 3, 2025 10:04
@zanieb zanieb added the breaking A breaking change label Jan 23, 2025
@zanieb zanieb added this to the v0.6.0 milestone Jan 23, 2025
@zanieb
Copy link
Member

zanieb commented Jan 23, 2025

Hey @Choudhry18 I fixed some merge conflicts and expanded the test cases.

I have one comment; otherwise this looks good to me!

Comment on lines 1048 to 1060
// 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'.
"###);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test failure is problematic — this needs to work still.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I mean uv python uninstall 3.11 --all would be confusing too — just used foo as a silly example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@zanieb zanieb self-requested a review February 8, 2025 02:38
@zanieb zanieb changed the base branch from main to tracking/060 February 13, 2025 18:30
@zanieb
Copy link
Member

zanieb commented Feb 13, 2025

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 uninstall behavior at all now? I feel like this change would definitely be simpler if we just handled UV_PYTHON on install and left uninstall explicit?

@zanieb
Copy link
Member

zanieb commented Feb 13, 2025

Exploring that in #11487

zanieb added a commit that referenced this pull request Feb 13, 2025
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]>
zanieb added a commit that referenced this pull request Feb 13, 2025
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]>
@zanieb zanieb deleted the branch astral-sh:tracking/060 February 13, 2025 22:17
@zanieb zanieb closed this Feb 13, 2025
zanieb added a commit that referenced this pull request Feb 13, 2025
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]>
loic-lescoat pushed a commit to loic-lescoat/uv that referenced this pull request Mar 2, 2025
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking A breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uv python install should recognize the UV_PYTHON environment variable

3 participants