Skip to content
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

Merged
merged 1 commit into from
Jun 10, 2024
Merged

Add uv toolchain list #4163

merged 1 commit into from
Jun 10, 2024

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jun 8, 2024

Adds the uv toolchain namespace and a list command to get us started.

❯ cargo run -q -- toolchain list
warning: `uv toolchain list` is experimental and may change without warning.
3.8.12   (cpython-3.8.12-macos-aarch64-none)
3.8.13   (cpython-3.8.13-macos-aarch64-none)
3.8.14   (cpython-3.8.14-macos-aarch64-none)
3.8.15   (cpython-3.8.15-macos-aarch64-none)
3.8.16   (cpython-3.8.16-macos-aarch64-none)
3.8.17   (cpython-3.8.17-macos-aarch64-none)
3.8.18   (cpython-3.8.18-macos-aarch64-none)
3.8.18   (cpython-3.8.18-macos-aarch64-none)
3.8.19   (cpython-3.8.19-macos-aarch64-none)
3.9.2    (cpython-3.9.2-macos-aarch64-none)
3.9.3    (cpython-3.9.3-macos-aarch64-none)
3.9.4    (cpython-3.9.4-macos-aarch64-none)
3.9.5    (cpython-3.9.5-macos-aarch64-none)
3.9.6    (cpython-3.9.6-macos-aarch64-none)
3.9.7    (cpython-3.9.7-macos-aarch64-none)
3.9.10   (cpython-3.9.10-macos-aarch64-none)
3.9.11   (cpython-3.9.11-macos-aarch64-none)
3.9.12   (cpython-3.9.12-macos-aarch64-none)
3.9.13   (cpython-3.9.13-macos-aarch64-none)
3.9.14   (cpython-3.9.14-macos-aarch64-none)
3.9.15   (cpython-3.9.15-macos-aarch64-none)
3.9.16   (cpython-3.9.16-macos-aarch64-none)
3.9.17   (cpython-3.9.17-macos-aarch64-none)
3.9.18   (cpython-3.9.18-macos-aarch64-none)
3.9.19   (cpython-3.9.19-macos-aarch64-none)
3.10.0   (cpython-3.10.0-macos-aarch64-none)
3.10.2   (cpython-3.10.2-macos-aarch64-none)
3.10.3   (cpython-3.10.3-macos-aarch64-none)
3.10.4   (cpython-3.10.4-macos-aarch64-none)
3.10.5   (cpython-3.10.5-macos-aarch64-none)
3.10.6   (cpython-3.10.6-macos-aarch64-none)
3.10.7   (cpython-3.10.7-macos-aarch64-none)
3.10.8   (cpython-3.10.8-macos-aarch64-none)
3.10.9   (cpython-3.10.9-macos-aarch64-none)
3.10.11  (cpython-3.10.11-macos-aarch64-none)
3.10.12  (cpython-3.10.12-macos-aarch64-none)
3.10.13  (cpython-3.10.13-macos-aarch64-none)
3.10.14  (cpython-3.10.14-macos-aarch64-none)
3.11.1   (cpython-3.11.1-macos-aarch64-none)
3.11.3   (cpython-3.11.3-macos-aarch64-none)
3.11.4   (cpython-3.11.4-macos-aarch64-none)
3.11.5   (cpython-3.11.5-macos-aarch64-none)
3.11.6   (cpython-3.11.6-macos-aarch64-none)
3.11.7   (cpython-3.11.7-macos-aarch64-none)
3.11.8   (cpython-3.11.8-macos-aarch64-none)
3.11.9   (cpython-3.11.9-macos-aarch64-none)
3.12.0   (cpython-3.12.0-macos-aarch64-none)
3.12.1   (cpython-3.12.1-macos-aarch64-none)
3.12.2   (cpython-3.12.2-macos-aarch64-none)
3.12.3   (cpython-3.12.3-macos-aarch64-none)

Closes #4189

@zanieb zanieb added the preview Experimental behavior label Jun 8, 2024
@zanieb zanieb changed the title zb/toolchain v i Add uv toolchain list Jun 8, 2024
@zanieb zanieb force-pushed the zb/toolchain-v-i branch 2 times, most recently from b21b37c to 76eb48d Compare June 8, 2024 15:53

/// List available toolchains.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn list(
Copy link
Member Author

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

crates/uv/src/cli.rs Outdated Show resolved Hide resolved
@zanieb zanieb force-pushed the zb/toolchain-v-i branch from 76eb48d to 7a05c31 Compare June 8, 2024 16:50
@zanieb zanieb mentioned this pull request Jun 8, 2024
Base automatically changed from zb/toolchain-v to main June 10, 2024 14:10
@zanieb zanieb force-pushed the zb/toolchain-v-i branch from 7a05c31 to b3f708c Compare June 10, 2024 14:11
@zanieb zanieb force-pushed the zb/toolchain-v-i branch from b3f708c to 943c963 Compare June 10, 2024 14:14
@zanieb zanieb merged commit c6da4f1 into main Jun 10, 2024
47 checks passed
@zanieb zanieb deleted the zb/toolchain-v-i branch June 10, 2024 14:22
zanieb added a commit that referenced this pull request Jun 10, 2024
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`.
Copy link
Contributor

@snowsignal snowsignal left a 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 😄

Comment on lines +29 to +39
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()
}
};
Copy link
Contributor

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();

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +48 to +63
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();
Copy link
Contributor

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(),
        ));
    }

zanieb added a commit that referenced this pull request Jun 10, 2024
Amends #4163 with review from Jane, thank you!

No behavior changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toolchain::find_all unwrap can panic
3 participants