1use std::path::{Path, PathBuf};
2
3use uv_pypi_types::Scheme;
4
5#[derive(Debug, Clone)]
8pub struct Prefix(PathBuf);
9
10impl Prefix {
11 pub fn scheme(&self, virtualenv: &Scheme) -> Scheme {
13 Scheme {
14 purelib: self.0.join(&virtualenv.purelib),
15 platlib: self.0.join(&virtualenv.platlib),
16 scripts: self.0.join(&virtualenv.scripts),
17 data: self.0.join(&virtualenv.data),
18 include: self.0.join(&virtualenv.include),
19 }
20 }
21
22 pub fn site_packages(&self, virtualenv: &Scheme) -> impl Iterator<Item = PathBuf> {
24 std::iter::once(self.0.join(&virtualenv.purelib))
25 }
26
27 pub fn init(&self, virtualenv: &Scheme) -> std::io::Result<()> {
29 for site_packages in self.site_packages(virtualenv) {
30 fs_err::create_dir_all(site_packages)?;
31 }
32 Ok(())
33 }
34
35 pub fn root(&self) -> &Path {
37 &self.0
38 }
39}
40
41impl From<PathBuf> for Prefix {
42 fn from(path: PathBuf) -> Self {
43 Self(path)
44 }
45}