feat: allow setting installer name other than `uv` (#2561)

## Summary

We would like to be able to configure the installer-name so that other
tools can co-exist with `uv`. In `pixi` we would like to use `pixi-uv`
as the installer name, for example, to be able to distinguish them from
packages installed by pure `uv`.
This commit is contained in:
Wolf Vollprecht 2024-03-20 10:36:49 -04:00 committed by GitHub
parent 00fc44012c
commit 1255c981a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -9,6 +9,7 @@ pub struct Installer<'a> {
venv: &'a PythonEnvironment,
link_mode: install_wheel_rs::linker::LinkMode,
reporter: Option<Box<dyn Reporter>>,
installer_name: Option<String>,
}
impl<'a> Installer<'a> {
@ -18,6 +19,7 @@ impl<'a> Installer<'a> {
venv,
link_mode: install_wheel_rs::linker::LinkMode::default(),
reporter: None,
installer_name: Some("uv".to_string()),
}
}
@ -36,6 +38,15 @@ impl<'a> Installer<'a> {
}
}
/// Set the `installer_name` to something other than `"uv"`.
#[must_use]
pub fn with_installer_name(self, installer_name: Option<String>) -> Self {
Self {
installer_name,
..self
}
}
/// Install a set of wheels into a Python virtual environment.
#[instrument(skip_all, fields(num_wheels = %wheels.len()))]
pub fn install(self, wheels: &[CachedDist]) -> Result<()> {
@ -52,7 +63,7 @@ impl<'a> Installer<'a> {
.map(pypi_types::DirectUrl::try_from)
.transpose()?
.as_ref(),
Some("uv"),
self.installer_name.as_deref(),
self.link_mode,
)
.with_context(|| format!("Failed to install: {} ({wheel})", wheel.filename()))?;