Skip to content

Commit 156dd51

Browse files
Replace Python installations during build upgrades (#21323)
When the resolved Python key matched an installed interpreter but its `BUILD` value differed, `uv python upgrade` recorded the new build metadata while reusing the existing directory, leaving the old interpreter bytes in place. Mark those keys for replacement before extraction, so the selected build is installed before its metadata is recorded. ```console $ uv python upgrade 3.12 Installed Python 3.12.<latest> ~ cpython-3.12.<latest>-<platform> $ python3.12 -c 'import sys; print(sys.version.split()[0])' 3.12.<latest> ``` Stacked on astral-sh#868. Co-authored-by: Zanie Blue <[email protected]>
1 parent 1a486d1 commit 156dd51

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ async fn perform_install(
599599

600600
// Download and unpack the Python versions concurrently
601601
let reporter = PythonDownloadReporter::new(printer, Some(downloads.len() as u64));
602+
let replacements = changelog.existing.clone();
602603

603604
let mut tasks = futures::stream::iter(&downloads)
604605
.map(async |download| {
@@ -610,7 +611,7 @@ async fn perform_install(
610611
&retry_policy,
611612
installations_dir,
612613
&scratch_dir,
613-
reinstall,
614+
reinstall || replacements.contains(download.key()),
614615
python_install_mirror.as_deref(),
615616
pypy_install_mirror.as_deref(),
616617
Some(&reporter),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3975,7 +3975,7 @@ fn python_install_upgrade_build_version() {
39753975
~ cpython-3.12.[LATEST]-[PLATFORM]
39763976
");
39773977

3978-
assert_eq!(
3978+
assert_ne!(
39793979
filetime::FileTime::from_last_modification_time(
39803980
&fs_err::metadata(&python_executable).unwrap()
39813981
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ fn python_upgrade_build_version() {
668668
~ cpython-3.12.[LATEST]-[PLATFORM]
669669
");
670670

671-
assert_eq!(
671+
assert_ne!(
672672
filetime::FileTime::from_last_modification_time(
673673
&fs_err::metadata(&python_executable).unwrap()
674674
),

0 commit comments

Comments
 (0)