Files
uv/crates/uv-resolver/src/fork_indexes.rs
T
Charlie Marsh 3774a656d7 Use parsed URLs for conflicting URL error message (#14380)
## Summary

There's a good example of the downside of using verbatim URLs here:
https://github.com/astral-sh/uv/pull/14197#discussion_r2163599625 (we
show two relative paths that point to the same directory, but it's not
clear from the error message).

The diff:

```
    2     2 │ ----- stdout -----
    3     3 │
    4     4 │ ----- stderr -----
    5     5 │ error: Requirements contain conflicting URLs for package `library` in all marker environments:
    6       │-- ../../library
    7       │-- ./library
          6 │+- file://[TEMP_DIR]/library
          7 │+- file://[TEMP_DIR]/library (editable)
```
2025-07-01 08:18:01 -04:00

39 lines
1.3 KiB
Rust

use rustc_hash::FxHashMap;
use uv_distribution_types::IndexMetadata;
use uv_normalize::PackageName;
use crate::ResolveError;
use crate::resolver::ResolverEnvironment;
/// See [`crate::resolver::ForkState`].
#[derive(Default, Debug, Clone)]
pub(crate) struct ForkIndexes(FxHashMap<PackageName, IndexMetadata>);
impl ForkIndexes {
/// Get the [`Index`] previously used for a package in this fork.
pub(crate) fn get(&self, package_name: &PackageName) -> Option<&IndexMetadata> {
self.0.get(package_name)
}
/// Check that this is the only [`Index`] used for this package in this fork.
pub(crate) fn insert(
&mut self,
package_name: &PackageName,
index: &IndexMetadata,
env: &ResolverEnvironment,
) -> Result<(), ResolveError> {
if let Some(previous) = self.0.insert(package_name.clone(), index.clone()) {
if &previous != index {
let mut conflicts = vec![previous.url, index.url.clone()];
conflicts.sort();
return Err(ResolveError::ConflictingIndexesForEnvironment {
package_name: package_name.clone(),
indexes: conflicts,
env: env.clone(),
});
}
}
Ok(())
}
}