Skip to content

Commit 96e1d2f

Browse files
committed
Revert "Avoid panicking when encountering an invalid Python version during uv python list (#7131)"
This reverts commit 8eff8aa.
1 parent d278e53 commit 96e1d2f

File tree

6 files changed

+12
-46
lines changed

6 files changed

+12
-46
lines changed

crates/uv-python/src/downloads.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,7 @@ impl ManagedPythonDownload {
529529
}
530530

531531
pub fn python_version(&self) -> PythonVersion {
532-
self.key
533-
.version()
534-
.expect("Managed Python downloads should always have valid versions")
532+
self.key.version()
535533
}
536534

537535
/// Return the [`Url`] to use when downloading the distribution. If a mirror is set via the

crates/uv-python/src/installation.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl PythonInstallationKey {
244244

245245
pub fn new_from_version(
246246
implementation: LenientImplementationName,
247-
version: PythonVersion,
247+
version: &PythonVersion,
248248
os: Os,
249249
arch: Arch,
250250
libc: Libc,
@@ -270,7 +270,7 @@ impl PythonInstallationKey {
270270
"{}.{}.{}{}",
271271
self.major, self.minor, self.patch, self.prerelease
272272
))
273-
.expect("Python versions for installation keys should always be valid}")
273+
.expect("Python installation keys must have valid Python versions")
274274
}
275275

276276
pub fn arch(&self) -> &Arch {
@@ -341,7 +341,7 @@ impl FromStr for PythonInstallationKey {
341341

342342
Ok(Self::new_from_version(
343343
implementation,
344-
version,
344+
&version,
345345
os,
346346
arch,
347347
libc,
@@ -359,12 +359,7 @@ impl Ord for PythonInstallationKey {
359359
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
360360
self.implementation
361361
.cmp(&other.implementation)
362-
.then_with(|| {
363-
self.major
364-
.cmp(&other.major)
365-
.then_with(|| self.minor.cmp(&other.minor))
366-
.then_with(|| self.patch.cmp(&other.patch))
367-
})
362+
.then_with(|| self.version().cmp(&other.version()))
368363
.then_with(|| self.os.to_string().cmp(&other.os.to_string()))
369364
.then_with(|| self.arch.to_string().cmp(&other.arch.to_string()))
370365
.then_with(|| self.libc.to_string().cmp(&other.libc.to_string()))

crates/uv-python/src/managed.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ impl ManagedPythonInstallation {
282282

283283
/// The [`PythonVersion`] of the toolchain.
284284
pub fn version(&self) -> PythonVersion {
285-
self.key
286-
.version()
287-
.expect("Managed Python installations should always have valid versions")
285+
self.key.version()
288286
}
289287

290288
pub fn implementation(&self) -> &ImplementationName {
@@ -331,17 +329,13 @@ impl ManagedPythonInstallation {
331329
let stdlib = if matches!(self.key.os, Os(target_lexicon::OperatingSystem::Windows)) {
332330
self.python_dir().join("Lib")
333331
} else {
334-
let version = self
335-
.key
336-
.version()
337-
.expect("Managed Python installations should always have valid versions");
338332
let python = if matches!(
339333
self.key.implementation,
340334
LenientImplementationName::Known(ImplementationName::PyPy)
341335
) {
342-
format!("pypy{}", version.python_version())
336+
format!("pypy{}", self.key.version().python_version())
343337
} else {
344-
format!("python{}", version.python_version())
338+
format!("python{}", self.key.version().python_version())
345339
};
346340
self.python_dir().join("lib").join(python)
347341
};

crates/uv/src/commands/python/install.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,7 @@ pub(crate) async fn install(
178178
"{}",
179179
format!(
180180
"Installed {} {}",
181-
format!(
182-
"Python {}",
183-
installed.version().expect(
184-
"Managed Python installations should always have valid versions"
185-
)
186-
)
187-
.bold(),
181+
format!("Python {}", installed.version()).bold(),
188182
format!("in {}", elapsed(start.elapsed())).dimmed()
189183
)
190184
.dimmed()

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::fmt::Write;
44
use anyhow::Result;
55
use owo_colors::OwoColorize;
66
use rustc_hash::FxHashSet;
7-
use tracing::warn;
87
use uv_cache::Cache;
98
use uv_fs::Simplified;
109
use uv_python::downloads::PythonDownloadRequest;
@@ -107,17 +106,9 @@ pub(crate) async fn list(
107106
}
108107
}
109108

110-
let version = match key.version() {
111-
Err(err) => {
112-
warn!("Excluding {key} due to invalid Python version: {err}");
113-
continue;
114-
}
115-
Ok(version) => version,
116-
};
117-
118109
// Only show the latest patch version for each download unless all were requested
119110
if !matches!(kind, Kind::System) {
120-
if let [major, minor, ..] = version.release() {
111+
if let [major, minor, ..] = key.version().release() {
121112
if !seen_minor.insert((
122113
*key.os(),
123114
*major,
@@ -131,7 +122,7 @@ pub(crate) async fn list(
131122
}
132123
}
133124
}
134-
if let [major, minor, patch] = version.release() {
125+
if let [major, minor, patch] = key.version().release() {
135126
if !seen_patch.insert((
136127
*key.os(),
137128
*major,

crates/uv/src/commands/python/uninstall.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,7 @@ async fn do_uninstall(
148148
"{}",
149149
format!(
150150
"Uninstalled {} {}",
151-
format!(
152-
"Python {}",
153-
uninstalled.version().expect(
154-
"Managed Python installations should always have valid versions"
155-
)
156-
)
157-
.bold(),
151+
format!("Python {}", uninstalled.version()).bold(),
158152
format!("in {}", elapsed(start.elapsed())).dimmed()
159153
)
160154
.dimmed()

0 commit comments

Comments
 (0)