-
Notifications
You must be signed in to change notification settings - Fork 140
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: warn on pypi conda clobbering #1353
Merged
ruben-arts
merged 16 commits into
prefix-dev:main
from
nichmor:feat/warn-on-pypi-conda-clobbering
May 17, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d2927f
feat: warn on clobbering of pypi to conda
nichmor dddac72
misc: fmt
nichmor f9dd9ef
misc: add test for clobbering warning
nichmor 1591c92
Merge branch 'main' into feat/warn-on-pypi-conda-clobbering
ruben-arts 7e4fc80
feat: warn on pypi clobbering
nichmor b1edde0
Merge branch 'feat/warn-on-pypi-conda-clobbering' of https://github.c…
nichmor f848038
Merge branch 'main' into feat/warn-on-pypi-conda-clobbering
nichmor 2560df8
feat: warn on pypi clobbering
nichmor 6cba70d
feat: warn on pypi clobbering
nichmor 5e04efb
feat: warn on pypi clobbering
nichmor 0f9ea30
update src/install_pypi.rs
nichmor 8d5d7ec
feat: switch to ahash
nichmor cd9ad48
misc: remove snapshot
nichmor ed0f27d
Merge branch 'main' into feat/warn-on-pypi-conda-clobbering
nichmor b7db013
misc: added comments for pypicondaclobber
nichmor eb6b014
misc: add comment why its important
nichmor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::path::PathBuf; | ||
|
||
use distribution_types::CachedDist; | ||
use rattler_conda_types::PrefixRecord; | ||
use uv_interpreter::PythonEnvironment; | ||
|
||
use crate::install_wheel::get_wheel_info; | ||
|
||
use ahash::{AHashMap, AHashSet}; | ||
|
||
#[derive(Default, Debug)] | ||
pub(crate) struct PypiCondaClobberRegistry { | ||
/// A registry of the paths of the installed conda paths and the package names | ||
paths_registry: AHashMap<PathBuf, rattler_conda_types::PackageName>, | ||
} | ||
|
||
impl PypiCondaClobberRegistry { | ||
/// Register the paths of the installed conda packages | ||
/// to later check if they are going to be clobbered by the installation of the wheels | ||
pub fn with_conda_packages(conda_packages: &[PrefixRecord]) -> Self { | ||
let mut registry = AHashMap::with_capacity(conda_packages.len() * 50); | ||
for record in conda_packages { | ||
for path in &record.paths_data.paths { | ||
registry.insert( | ||
path.relative_path.clone(), | ||
record.repodata_record.package_record.name.clone(), | ||
); | ||
} | ||
} | ||
Self { | ||
paths_registry: registry, | ||
} | ||
} | ||
|
||
/// Check if the installation of the wheels is going to clobber any installed conda package | ||
/// and return the names of the packages that are going to be clobbered | ||
/// this allow to warn the user about the overwriting of already installed packages | ||
/// in case of wrong mapping data | ||
/// or malicious packages | ||
pub fn clobber_on_instalation( | ||
self, | ||
wheels: Vec<CachedDist>, | ||
venv: &PythonEnvironment, | ||
) -> miette::Result<Option<AHashSet<String>>> { | ||
let mut clobber_packages: AHashSet<String> = AHashSet::default(); | ||
|
||
for wheel in wheels { | ||
let Ok(Some(whl_info)) = get_wheel_info(wheel.path(), venv) else { | ||
continue; | ||
}; | ||
|
||
for entry in whl_info.0 { | ||
let path_to_clobber = whl_info.1.join(entry.path); | ||
|
||
if let Some(name) = self.paths_registry.get(&path_to_clobber) { | ||
clobber_packages.insert(name.as_normalized().to_string()); | ||
} | ||
} | ||
} | ||
if clobber_packages.is_empty() { | ||
return Ok(None); | ||
} | ||
Ok(Some(clobber_packages)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe what it returns? And why this is important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done