Skip to content

Commit 0f03963

Browse files
authored
Skip loading Python download metadata when listing installed interpreters (#21925)
the metadata is not necessary for listing installed pythons, so skip loading it. benchmarking locally: Case | Before | After | Reduction -- | -- | -- | -- --only-installed, two interpreters | 37.38 ms | 15.55 ms | 58.4% --only-installed, no interpreters | 36.24 ms | 14.62 ms | 59.7% --only-downloads 3.12 control | 34.42 ms | 34.32 ms | 0.3%
1 parent 6d1b266 commit 0f03963

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

‎crates/uv/src/commands/python/list.rs‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ pub(crate) async fn list(
7979
PythonDownloadRequest::from_request(request.as_ref().unwrap_or(&PythonRequest::Any))
8080
};
8181

82-
let download_list =
83-
ManagedPythonDownloadList::new(client_builder, cache, python_downloads_json_url.as_deref())
84-
.await?;
85-
let mut output = BTreeSet::new();
86-
if let Some(base_download_request) = base_download_request {
87-
let download_request = match kinds {
82+
let download_request = if let Some(base_download_request) = base_download_request {
83+
match kinds {
8884
PythonListKinds::Installed => None,
8985
PythonListKinds::Downloads => Some(if all_platforms {
9086
base_download_request
@@ -109,13 +105,22 @@ pub(crate) async fn list(
109105
}
110106
}
111107
// Include pre-release versions
112-
.map(|request| request.with_prereleases(true));
108+
.map(|request| request.with_prereleases(true))
109+
} else {
110+
None
111+
};
112+
113+
let mut output = BTreeSet::new();
114+
if let Some(download_request) = download_request {
115+
let download_list = ManagedPythonDownloadList::new(
116+
client_builder,
117+
cache,
118+
python_downloads_json_url.as_deref(),
119+
)
120+
.await?;
113121

114-
let downloads = download_request
115-
.as_ref()
116-
.map(|request| download_list.iter_matching(request))
117-
.into_iter()
118-
.flatten()
122+
let downloads = download_list
123+
.iter_matching(&download_request)
119124
// TODO(zanieb): Add a way to show debug downloads, we just hide them for now
120125
.filter(|download| !download.key().variant().is_debug());
121126

‎crates/uv/tests/python/python_list.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,31 @@ fn python_list_managed_symlinks() {
560560
");
561561
}
562562

563+
#[tokio::test]
564+
async fn python_list_only_installed_skips_download_metadata() {
565+
let context = uv_test::test_context_with_versions!(&["3.12"])
566+
.with_filtered_python_symlinks()
567+
.with_filtered_python_keys()
568+
.with_collapsed_whitespace();
569+
let server = MockServer::start().await;
570+
571+
Mock::given(method("GET"))
572+
.and(path("/"))
573+
.respond_with(ResponseTemplate::new(200).set_body_raw("{", "application/json"))
574+
.expect(0)
575+
.mount(&server)
576+
.await;
577+
578+
uv_snapshot!(context.filters(), context.python_list()
579+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS)
580+
.arg("--only-installed")
581+
.arg("--python-downloads-json-url").arg(server.uri()), @"
582+
exit_code: 0 (success)
583+
----- stdout -----
584+
cpython-3.12.[X]-[PLATFORM] [PYTHON-3.12]
585+
");
586+
}
587+
563588
#[tokio::test]
564589
async fn python_list_remote_python_downloads_json_url() -> Result<()> {
565590
let context = uv_test::test_context_with_versions!(&[]);

0 commit comments

Comments
 (0)