Skip to content

Commit b7167dc

Browse files
authored
Fix uv python install --reinstall when the version is not yet installed (#12124)
I noticed this was failing to perform the install
1 parent 553bccc commit b7167dc

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,17 @@ pub(crate) async fn install(
205205
Vec::with_capacity(existing_installations.len() + requests.len());
206206

207207
for request in &requests {
208-
if existing_installations.is_empty() {
208+
let mut matching_installations = existing_installations
209+
.iter()
210+
.filter(|installation| request.matches_installation(installation))
211+
.peekable();
212+
213+
if matching_installations.peek().is_none() {
209214
debug!("No installation found for request `{}`", request.cyan());
210215
unsatisfied.push(Cow::Borrowed(request));
211216
}
212217

213-
for installation in existing_installations
214-
.iter()
215-
.filter(|installation| request.matches_installation(installation))
216-
{
218+
for installation in matching_installations {
217219
changelog.existing.insert(installation.key().clone());
218220
if matches!(&request.request, &PythonRequest::Any) {
219221
// Construct a install request matching the existing installation
@@ -300,6 +302,7 @@ pub(crate) async fn install(
300302
.build();
301303
let reporter = PythonDownloadReporter::new(printer, downloads.len() as u64);
302304
let mut tasks = FuturesUnordered::new();
305+
303306
for download in &downloads {
304307
tasks.push(async {
305308
(

crates/uv/tests/it/python_install.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn python_reinstall() {
9999
.with_managed_python_dirs();
100100

101101
// Install a couple versions
102-
uv_snapshot!(context.filters(), context.python_install().arg("3.12").arg("3.13"), @r###"
102+
uv_snapshot!(context.filters(), context.python_install().arg("3.12").arg("3.13"), @r"
103103
success: true
104104
exit_code: 0
105105
----- stdout -----
@@ -108,21 +108,21 @@ fn python_reinstall() {
108108
Installed 2 versions in [TIME]
109109
+ cpython-3.12.9-[PLATFORM]
110110
+ cpython-3.13.2-[PLATFORM]
111-
"###);
111+
");
112112

113113
// Reinstall a single version
114-
uv_snapshot!(context.filters(), context.python_install().arg("3.13").arg("--reinstall"), @r###"
114+
uv_snapshot!(context.filters(), context.python_install().arg("3.13").arg("--reinstall"), @r"
115115
success: true
116116
exit_code: 0
117117
----- stdout -----
118118
119119
----- stderr -----
120120
Installed Python 3.13.2 in [TIME]
121121
~ cpython-3.13.2-[PLATFORM]
122-
"###);
122+
");
123123

124124
// Reinstall multiple versions
125-
uv_snapshot!(context.filters(), context.python_install().arg("--reinstall"), @r###"
125+
uv_snapshot!(context.filters(), context.python_install().arg("--reinstall"), @r"
126126
success: true
127127
exit_code: 0
128128
----- stdout -----
@@ -131,7 +131,18 @@ fn python_reinstall() {
131131
Installed 2 versions in [TIME]
132132
~ cpython-3.12.9-[PLATFORM]
133133
~ cpython-3.13.2-[PLATFORM]
134-
"###);
134+
");
135+
136+
// Reinstalling a version that is not installed should also work
137+
uv_snapshot!(context.filters(), context.python_install().arg("3.11").arg("--reinstall"), @r"
138+
success: true
139+
exit_code: 0
140+
----- stdout -----
141+
142+
----- stderr -----
143+
Installed Python 3.11.11 in [TIME]
144+
+ cpython-3.11.11-[PLATFORM]
145+
");
135146
}
136147

137148
#[test]
@@ -142,7 +153,7 @@ fn python_reinstall_patch() {
142153
.with_managed_python_dirs();
143154

144155
// Install a couple patch versions
145-
uv_snapshot!(context.filters(), context.python_install().arg("3.12.6").arg("3.12.7"), @r###"
156+
uv_snapshot!(context.filters(), context.python_install().arg("3.12.6").arg("3.12.7"), @r"
146157
success: true
147158
exit_code: 0
148159
----- stdout -----
@@ -151,20 +162,20 @@ fn python_reinstall_patch() {
151162
Installed 2 versions in [TIME]
152163
+ cpython-3.12.6-[PLATFORM]
153164
+ cpython-3.12.7-[PLATFORM]
154-
"###);
165+
");
155166

156167
// Reinstall all "3.12" versions
157168
// TODO(zanieb): This doesn't work today, because we need this to install the "latest" as there
158169
// is no workflow for `--upgrade` yet
159-
uv_snapshot!(context.filters(), context.python_install().arg("3.12").arg("--reinstall"), @r###"
170+
uv_snapshot!(context.filters(), context.python_install().arg("3.12").arg("--reinstall"), @r"
160171
success: true
161172
exit_code: 0
162173
----- stdout -----
163174
164175
----- stderr -----
165176
Installed Python 3.12.9 in [TIME]
166177
+ cpython-3.12.9-[PLATFORM]
167-
"###);
178+
");
168179
}
169180

170181
#[test]

0 commit comments

Comments
 (0)