mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-23 16:51:40 +00:00
## Summary Based on feedback in https://github.com/astral-sh/uv/pull/3257#issuecomment-2078560574.
38 lines
950 B
Rust
38 lines
950 B
Rust
use std::path::{Path, PathBuf};
|
|
|
|
use pypi_types::Scheme;
|
|
|
|
/// A `--target` directory into which packages can be installed, separate from a virtual environment
|
|
/// or system Python interpreter.
|
|
#[derive(Debug, Clone)]
|
|
pub struct Target(PathBuf);
|
|
|
|
impl Target {
|
|
/// Return the [`Scheme`] for the `--target` directory.
|
|
pub fn scheme(&self) -> Scheme {
|
|
Scheme {
|
|
purelib: self.0.clone(),
|
|
platlib: self.0.clone(),
|
|
scripts: self.0.join("bin"),
|
|
data: self.0.clone(),
|
|
include: self.0.join("include"),
|
|
}
|
|
}
|
|
|
|
/// Initialize the `--target` directory.
|
|
pub fn init(&self) -> std::io::Result<()> {
|
|
fs_err::create_dir_all(&self.0)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Return the path to the `--target` directory.
|
|
pub fn root(&self) -> &Path {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl From<PathBuf> for Target {
|
|
fn from(path: PathBuf) -> Self {
|
|
Self(path)
|
|
}
|
|
}
|