-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add support for global uv python pin
#12115
base: main
Are you sure you want to change the base?
Conversation
crates/uv/tests/it/python_pin.rs
Outdated
// Request Python 3.11 for local .python-version | ||
uv_snapshot!(context.filters(), context.python_pin().arg("3.11").env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
Pinned `.python-version` to `3.11` | ||
----- stderr ----- | ||
"###); |
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.
We might want to assert specific file contents after this snapshot? Like the global one is unchanged and the local one is present?
crates/uv/tests/it/tool_install.rs
Outdated
// On Windows, we can't snapshot an executable file. | ||
#[cfg(not(windows))] | ||
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
// Should run black in the virtual environment | ||
assert_snapshot!(fs_err::read_to_string(executable).unwrap(), @r###" | ||
#![TEMP_DIR]/tools/black/bin/python | ||
# -*- coding: utf-8 -*- | ||
import sys | ||
from black import patched_main | ||
if __name__ == "__main__": | ||
if sys.argv[0].endswith("-script.pyw"): | ||
sys.argv[0] = sys.argv[0][:-11] | ||
elif sys.argv[0].endswith(".exe"): | ||
sys.argv[0] = sys.argv[0][:-4] | ||
sys.exit(patched_main()) | ||
"###); | ||
|
||
}); |
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.
We probably don't need repeated coverage for things like this here, we just need to test that the Python version is respected and this adds a lot of noise.
crates/uv/tests/it/tool_install.rs
Outdated
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
// We should have a tool receipt | ||
assert_snapshot!(fs_err::read_to_string(tool_dir.join("black").join("uv-receipt.toml")).unwrap(), @r###" | ||
[tool] | ||
requirements = [{ name = "black" }] | ||
entrypoints = [ | ||
{ name = "black", install-path = "[TEMP_DIR]/bin/black" }, | ||
{ name = "blackd", install-path = "[TEMP_DIR]/bin/blackd" }, | ||
] | ||
[tool.options] | ||
exclude-newer = "2024-03-25T00:00:00Z" | ||
"###); | ||
}); |
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.
We don't capture the Python version in the receipt. This is actually relevant. What happens if the global Python version changes then you reinstall or upgrade? Test coverage for that would good. I think it's fine to respect the changed global default, personally.
return Ok(None); | ||
// Not found in directory or its ancestors. Looking in user-level config. | ||
return Ok(match user_uv_config_dir() { | ||
Some(user_dir) => Self::discover_user_config(user_dir, options) |
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 wonder if we should co-locate this with the uv.toml
? Like, if
Line 140 in ba74b9e
pub fn system_config_file() -> Option<PathBuf> { |
--system
flag separately in the future once we have more feedback.
I do lean towards |
These changes add support for
This adds the specified version to a
.python-version
file in the user-level config directory. uv will now use the user-level version as a fallback if no version is found in the project directory or its ancestors.Open question: is
--global
the correct parameter here?--user
is more precise, but might not communicate the intent as clearly.TODO: User documentation.
Closes #4972