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

feat: remove empty folders on python uninstall #512

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 33 additions & 38 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,11 @@ async fn update_python_distributions(
let site_package_path = install_paths.site_packages();

for python_distribution in python_distributions_to_remove {
tracing::info!(
"uninstalling python package {}-{}",
&python_distribution.name,
&python_distribution.version
);
let relative_dist_info = python_distribution
.dist_info
.strip_prefix(site_package_path)
.expect("the dist-info path must be a sub-path of the site-packages path");
rip::uninstall::uninstall_distribution(&prefix.root().join(site_package_path), relative_dist_info)
.into_diagnostic()
.with_context(|| format!("could not uninstall python package {}-{}. Manually remove the `.pixi/env` folder and try again.", &python_distribution.name, &python_distribution.version))?;

// HACK: Also remove the HASH file that pixi writes. Ignore the error if its there. We
// should probably actually add this file to the RECORD.
let _ = std::fs::remove_file(
prefix
.root()
.join(&python_distribution.dist_info)
.join("HASH"),
);
uninstall_pixi_installed_distribution(
&prefix,
&site_package_path,
&python_distribution,
)?;
}
}

Expand Down Expand Up @@ -519,35 +503,46 @@ fn remove_old_python_distributions(
// Remove the python packages
let site_package_path = install_paths.site_packages();
for python_package in current_python_packages {
tracing::info!(
"uninstalling python package from previous python version {}-{}",
&python_package.name,
&python_package.version
);

pb.set_message(format!(
"{} {}",
&python_package.name, &python_package.version
));

let relative_dist_info = python_package
.dist_info
.strip_prefix(site_package_path)
.expect("the dist-info path must be a sub-path of the site-packages path");
rip::uninstall::uninstall_distribution(&prefix.root().join(site_package_path), relative_dist_info)
.into_diagnostic()
.with_context(|| format!("could not uninstall python package {}-{}. Manually remove the `.pixi/env` folder and try again.", &python_package.name, &python_package.version))?;

// HACK: Also remove the HASH file that pixi writes. Ignore the error if its there. We
// should probably actually add this file to the RECORD.
let _ = std::fs::remove_file(prefix.root().join(&python_package.dist_info).join("HASH"));
uninstall_pixi_installed_distribution(&prefix, &site_package_path, &python_package)?;

pb.inc(1);
}

Ok(())
}

/// Uninstalls a python distribution that was previously installed by pixi.
fn uninstall_pixi_installed_distribution(
prefix: &&Prefix,
site_package_path: &&Path,
python_package: &Distribution,
) -> miette::Result<()> {
tracing::info!(
"uninstalling python package {}-{}",
&python_package.name,
&python_package.version
);
let relative_dist_info = python_package
.dist_info
.strip_prefix(site_package_path)
.expect("the dist-info path must be a sub-path of the site-packages path");

// HACK: Also remove the HASH file that pixi writes. Ignore the error if its there. We
// should probably actually add this file to the RECORD.
let _ = std::fs::remove_file(prefix.root().join(&python_package.dist_info).join("HASH"));

rip::uninstall::uninstall_distribution(&prefix.root().join(site_package_path), relative_dist_info)
.into_diagnostic()
.with_context(|| format!("could not uninstall python package {}-{}. Manually remove the `.pixi/env` folder and try again.", &python_package.name, &python_package.version))?;

Ok(())
}

/// Determine which python packages we can leave untouched and which python packages should be
/// removed.
fn determine_python_distributions_to_remove_and_install<'p>(
Expand Down