mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-18 19:21:46 +00:00
Remove __pycache__ directories when uninstalling (#397)
According to the [packaging documentation](https://packaging.python.org/en/latest/specifications/binary-distribution-format/#binary-distribution-format), "uninstallers should be smart enough to remove .pyc even if it is not mentioned in RECORD". Previously, we weren't handling this case, so if you installed via Puffin, then imported a file (to trigger bytecode compilation), then uninstalled, we'd leave spare `__pycache__` directories around. Closes https://github.com/astral-sh/puffin/issues/395.
This commit is contained in:
parent
63f7f65190
commit
e8108cb28b
3 changed files with 94 additions and 1 deletions
|
|
@ -64,6 +64,19 @@ pub fn uninstall_wheel(dist_info: &Path) -> Result<Uninstall, Error> {
|
|||
break;
|
||||
}
|
||||
|
||||
// If the directory contains a `__pycache__` directory, always remove it. `__pycache__`
|
||||
// may or may not be listed in the RECORD, but installers are expected to be smart
|
||||
// enough to remove it either way.
|
||||
let pycache = path.join("__pycache__");
|
||||
match fs::remove_dir_all(&pycache) {
|
||||
Ok(()) => {
|
||||
debug!("Removed directory: {}", pycache.display());
|
||||
dir_count += 1;
|
||||
}
|
||||
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
|
||||
Err(err) => return Err(err.into()),
|
||||
}
|
||||
|
||||
// Try to read from the directory. If it doesn't exist, assume we deleted it in a
|
||||
// previous iteration.
|
||||
let mut read_dir = match fs::read_dir(path) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue