-
Notifications
You must be signed in to change notification settings - Fork 1k
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-tool/install: ignore existing environments on interpreter mismatch #7451
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2074,7 +2074,7 @@ fn tool_install_upgrade() { | |
|
||
/// Test reinstalling tools with varying `--python` requests. | ||
#[test] | ||
fn tool_install_python_request() { | ||
fn tool_install_python_requests() { | ||
let context = TestContext::new_with_versions(&["3.11", "3.12"]) | ||
.with_filtered_counts() | ||
.with_filtered_exe_suffix(); | ||
|
@@ -2122,7 +2122,7 @@ fn tool_install_python_request() { | |
`black` is already installed | ||
"###); | ||
|
||
// Install with Python 3.11 (incompatible). | ||
// // Install with Python 3.11 (incompatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.11") | ||
|
@@ -2135,7 +2135,7 @@ fn tool_install_python_request() { | |
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Existing environment for `black` does not satisfy the requested Python interpreter | ||
Ignoring existing environment for `black`: the requested Python interpreter does not match the environment interpreter | ||
Resolved [N] packages in [TIME] | ||
Prepared [N] packages in [TIME] | ||
Installed [N] packages in [TIME] | ||
|
@@ -2149,6 +2149,150 @@ fn tool_install_python_request() { | |
"###); | ||
} | ||
|
||
/// Test reinstalling tools with varying `--python` and | ||
/// `--python-preference` parameters. | ||
#[ignore = "https://github.com/astral-sh/uv/issues/7473"] | ||
#[test] | ||
fn tool_install_python_preference() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let context = TestContext::new_with_versions(&["3.11", "3.12"]) | ||
.with_filtered_counts() | ||
.with_filtered_exe_suffix(); | ||
let tool_dir = context.temp_dir.child("tools"); | ||
let bin_dir = context.temp_dir.child("bin"); | ||
|
||
// Install `black`. | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.12") | ||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Resolved [N] packages in [TIME] | ||
Prepared [N] packages in [TIME] | ||
Installed [N] packages in [TIME] | ||
+ black==24.3.0 | ||
+ click==8.1.7 | ||
+ mypy-extensions==1.0.0 | ||
+ packaging==24.0 | ||
+ pathspec==0.12.1 | ||
+ platformdirs==4.2.0 | ||
Installed 2 executables: black, blackd | ||
"###); | ||
|
||
// Install with Python 3.12 (compatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.12") | ||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
`black` is already installed | ||
"###); | ||
|
||
// Install with system Python 3.11 (different version, incompatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.11") | ||
.arg("--python-preference") | ||
.arg("only-system") | ||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Ignoring existing environment for `black`: the requested Python interpreter does not match the environment interpreter | ||
Resolved [N] packages in [TIME] | ||
Prepared [N] packages in [TIME] | ||
Installed [N] packages in [TIME] | ||
+ black==24.3.0 | ||
+ click==8.1.7 | ||
+ mypy-extensions==1.0.0 | ||
+ packaging==24.0 | ||
+ pathspec==0.12.1 | ||
+ platformdirs==4.2.0 | ||
Installed 2 executables: black, blackd | ||
"###); | ||
|
||
// Install with system Python 3.11 (compatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.11") | ||
.arg("--python-preference") | ||
.arg("only-system") | ||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
`black` is already installed | ||
"###); | ||
|
||
// Install with managed Python 3.11 (different source, incompatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.11") | ||
.arg("--python-preference") | ||
.arg("only-managed") | ||
Comment on lines
+2254
to
+2255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't super obvious, but I think this can fetch a Python managed version during the test which we currently avoid (downstream packagers do not like it). I think this test may also be brittle depending on the developer's machine — the test context is happy with whatever Python versions it can find whether they are system or managed. I am not sure how to properly write a test for this though :/ it seems like a pain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of your time, I'd recommend omitting test coverage and opening an issue to add it. We'll need to consider a comprehensive solution here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can split the new cases apart in a different test and mark it as ignored, if you like. That should still allow running the test manually if needed, but won't impact packagers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Ignoring existing environment for `black`: the requested Python interpreter does not match the environment interpreter | ||
Resolved [N] packages in [TIME] | ||
Installed [N] packages in [TIME] | ||
+ black==24.3.0 | ||
+ click==8.1.7 | ||
+ mypy-extensions==1.0.0 | ||
+ packaging==24.0 | ||
+ pathspec==0.12.1 | ||
+ platformdirs==4.2.0 | ||
Installed 2 executables: black, blackd | ||
"###); | ||
|
||
// Install with managed Python 3.11 (compatible). | ||
uv_snapshot!(context.filters(), context.tool_install() | ||
.arg("-p") | ||
.arg("3.11") | ||
.arg("--python-preference") | ||
.arg("only-managed") | ||
.arg("black") | ||
.env("UV_TOOL_DIR", tool_dir.as_os_str()) | ||
.env("XDG_BIN_HOME", bin_dir.as_os_str()) | ||
.env("PATH", bin_dir.as_os_str()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
`black` is already installed | ||
"###); | ||
} | ||
|
||
/// Test preserving a tool environment when new but incompatible requirements are requested. | ||
#[test] | ||
fn tool_install_preserve_environment() { | ||
|
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.
Note: drive-by change to make debug logs more uniform. After this, the output now looks like this: