-
Notifications
You must be signed in to change notification settings - Fork 1.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
Add uv toolchain list
#4163
Add uv toolchain list
#4163
Conversation
b21b37c
to
76eb48d
Compare
|
||
/// List available toolchains. | ||
#[allow(clippy::too_many_arguments)] | ||
pub(crate) async fn list( |
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.
This implementation feels kind of sloppy. cc @snowsignal maybe a good one for you to critique :)
Adds a command (following #4163) to download and install specific toolchains. While we fetch toolchains on demand, this is useful for, e.g., pre-downloading a toolchain in a Docker image build. ~I kind of think we should call this `install` instead of `fetch`~ I changed the name from `fetch` to `install`.
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.
Leaving a post-merge review with some suggestions for the future 😄
let downloads = match includes { | ||
ToolchainListIncludes::All => { | ||
let request = PythonDownloadRequest::default(); | ||
request.iter_downloads().collect() | ||
} | ||
ToolchainListIncludes::Installed => Vec::new(), | ||
ToolchainListIncludes::Default => { | ||
let request = PythonDownloadRequest::from_env()?; | ||
request.iter_downloads().collect() | ||
} | ||
}; |
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.
This could be refactored to avoid an allocation:
let download_request = match includes {
ToolchainListIncludes::All => Some(PythonDownloadRequest::default()),
ToolchainListIncludes::Installed => None,
ToolchainListIncludes::Default => Some(PythonDownloadRequest::from_env()?)
};
let downloads = download_request
.as_ref()
.map(|request| request.iter_downloads())
.into_iter()
.flatten();
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.
Thanks!
let mut output = Vec::new(); | ||
for toolchain in installed { | ||
output.push(( | ||
toolchain.python_version().deref().version.clone(), | ||
toolchain.key().to_owned(), | ||
)); | ||
} | ||
for download in downloads { | ||
output.push(( | ||
download.python_version().deref().version.clone(), | ||
download.key().to_owned(), | ||
)); | ||
} | ||
|
||
output.sort(); | ||
output.dedup(); |
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 could use BTreeSet
here to skip the sorting / de-duplication steps.
let mut output = BTreeSet::new();
for toolchain in installed {
output.insert((
toolchain.python_version().version().clone(),
toolchain.key().to_owned(),
));
}
for download in downloads {
output.insert((
download.python_version().version().clone(),
download.key().to_owned(),
));
}
Amends #4163 with review from Jane, thank you! No behavior changes.
Adds the
uv toolchain
namespace and alist
command to get us started.Closes #4189