diff --git a/crates/gourgeist/src/lib.rs b/crates/gourgeist/src/lib.rs index 9ba067bda..4034c314f 100644 --- a/crates/gourgeist/src/lib.rs +++ b/crates/gourgeist/src/lib.rs @@ -5,7 +5,7 @@ use camino::{FromPathError, Utf8Path}; use thiserror::Error; use platform_host::PlatformError; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; pub use crate::bare::create_bare_venv; @@ -52,12 +52,12 @@ pub fn create_venv( interpreter: Interpreter, prompt: Prompt, extra_cfg: Vec<(String, String)>, -) -> Result { +) -> Result { let location: &Utf8Path = location .try_into() .map_err(|err: FromPathError| err.into_io_error())?; let paths = create_bare_venv(location, &interpreter, prompt, extra_cfg)?; - Ok(Virtualenv::from_interpreter( + Ok(PythonEnvironment::from_interpreter( interpreter, paths.root.as_std_path(), )) diff --git a/crates/uv-build/src/lib.rs b/crates/uv-build/src/lib.rs index 0b67a6b41..803241bf6 100644 --- a/crates/uv-build/src/lib.rs +++ b/crates/uv-build/src/lib.rs @@ -29,7 +29,7 @@ use tracing::{debug, info_span, instrument, Instrument}; use distribution_types::Resolution; use pep508_rs::Requirement; use uv_fs::Normalized; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; use uv_traits::{BuildContext, BuildKind, ConfigSettings, SetupPyStrategy, SourceBuildTrait}; /// e.g. `pygraphviz/graphviz_wrap.c:3020:10: fatal error: graphviz/cgraph.h: No such file or directory` @@ -316,7 +316,7 @@ pub struct SourceBuild { /// If performing a PEP 517 build, the backend to use. pep517_backend: Option, /// The virtual environment in which to build the source distribution. - venv: Virtualenv, + venv: PythonEnvironment, /// Populated if `prepare_metadata_for_build_wheel` was called. /// /// > If the build frontend has previously called prepare_metadata_for_build_wheel and depends @@ -757,7 +757,7 @@ fn escape_path_for_python(path: &Path) -> String { /// Not a method because we call it before the builder is completely initialized async fn create_pep517_build_environment( source_tree: &Path, - venv: &Virtualenv, + venv: &PythonEnvironment, pep517_backend: &Pep517Backend, build_context: &impl BuildContext, package_id: &str, @@ -846,7 +846,7 @@ async fn create_pep517_build_environment( /// It is the caller's responsibility to create an informative span. async fn run_python_script( - venv: &Virtualenv, + venv: &PythonEnvironment, script: &str, source_tree: &Path, ) -> Result { diff --git a/crates/uv-dev/src/build.rs b/crates/uv-dev/src/build.rs index efe125b65..feb5bf604 100644 --- a/crates/uv-dev/src/build.rs +++ b/crates/uv-dev/src/build.rs @@ -12,7 +12,7 @@ use uv_cache::{Cache, CacheArgs}; use uv_client::{FlatIndex, RegistryClientBuilder}; use uv_dispatch::BuildDispatch; use uv_installer::NoBinary; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_resolver::InMemoryIndex; use uv_traits::{BuildContext, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -54,7 +54,7 @@ pub(crate) async fn build(args: BuildArgs) -> Result { let cache = Cache::try_from(args.cache_args)?; let platform = Platform::current()?; - let venv = Virtualenv::from_env(platform, &cache)?; + let venv = PythonEnvironment::from_virtualenv(platform, &cache)?; let client = RegistryClientBuilder::new(cache.clone()).build(); let index_urls = IndexLocations::default(); let flat_index = FlatIndex::default(); diff --git a/crates/uv-dev/src/install_many.rs b/crates/uv-dev/src/install_many.rs index da924508d..43028b892 100644 --- a/crates/uv-dev/src/install_many.rs +++ b/crates/uv-dev/src/install_many.rs @@ -21,7 +21,7 @@ use uv_client::{FlatIndex, RegistryClient, RegistryClientBuilder}; use uv_dispatch::BuildDispatch; use uv_distribution::RegistryWheelIndex; use uv_installer::{Downloader, NoBinary}; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_normalize::PackageName; use uv_resolver::{DistFinder, InMemoryIndex}; use uv_traits::{BuildContext, ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -56,7 +56,7 @@ pub(crate) async fn install_many(args: InstallManyArgs) -> Result<()> { let cache = Cache::try_from(args.cache_args)?; let platform = Platform::current()?; - let venv = Virtualenv::from_env(platform, &cache)?; + let venv = PythonEnvironment::from_virtualenv(platform, &cache)?; let client = RegistryClientBuilder::new(cache.clone()).build(); let index_locations = IndexLocations::default(); let flat_index = FlatIndex::default(); @@ -112,7 +112,7 @@ async fn install_chunk( build_dispatch: &BuildDispatch<'_>, tags: &Tags, client: &RegistryClient, - venv: &Virtualenv, + venv: &PythonEnvironment, index_locations: &IndexLocations, ) -> Result<()> { let resolution: Vec<_> = DistFinder::new( diff --git a/crates/uv-dev/src/resolve_cli.rs b/crates/uv-dev/src/resolve_cli.rs index cdb3113c4..6af1ff9be 100644 --- a/crates/uv-dev/src/resolve_cli.rs +++ b/crates/uv-dev/src/resolve_cli.rs @@ -16,7 +16,7 @@ use uv_cache::{Cache, CacheArgs}; use uv_client::{FlatIndex, FlatIndexClient, RegistryClientBuilder}; use uv_dispatch::BuildDispatch; use uv_installer::NoBinary; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver}; use uv_traits::{ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -55,7 +55,7 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> Result<()> { let cache = Cache::try_from(args.cache_args)?; let platform = Platform::current()?; - let venv = Virtualenv::from_env(platform, &cache)?; + let venv = PythonEnvironment::from_virtualenv(platform, &cache)?; let index_locations = IndexLocations::new( Some(args.index_url), args.extra_index_url, diff --git a/crates/uv-dev/src/resolve_many.rs b/crates/uv-dev/src/resolve_many.rs index f5718d82e..ebcb86cf4 100644 --- a/crates/uv-dev/src/resolve_many.rs +++ b/crates/uv-dev/src/resolve_many.rs @@ -18,7 +18,7 @@ use uv_cache::{Cache, CacheArgs}; use uv_client::{FlatIndex, OwnedArchive, RegistryClient, RegistryClientBuilder}; use uv_dispatch::BuildDispatch; use uv_installer::NoBinary; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_normalize::PackageName; use uv_resolver::InMemoryIndex; use uv_traits::{BuildContext, ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -73,7 +73,7 @@ pub(crate) async fn resolve_many(args: ResolveManyArgs) -> Result<()> { let total = requirements.len(); let platform = Platform::current()?; - let venv = Virtualenv::from_env(platform, &cache)?; + let venv = PythonEnvironment::from_virtualenv(platform, &cache)?; let in_flight = InFlight::default(); let client = RegistryClientBuilder::new(cache.clone()).build(); diff --git a/crates/uv-dispatch/src/lib.rs b/crates/uv-dispatch/src/lib.rs index 3f3ec1330..4a0bf228c 100644 --- a/crates/uv-dispatch/src/lib.rs +++ b/crates/uv-dispatch/src/lib.rs @@ -16,7 +16,7 @@ use uv_build::{SourceBuild, SourceBuildContext}; use uv_cache::Cache; use uv_client::{FlatIndex, RegistryClient}; use uv_installer::{Downloader, Installer, NoBinary, Plan, Planner, Reinstall, SitePackages}; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; use uv_resolver::{InMemoryIndex, Manifest, Options, Resolver}; use uv_traits::{BuildContext, BuildKind, ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -138,7 +138,7 @@ impl<'a> BuildContext for BuildDispatch<'a> { fn install<'data>( &'data self, resolution: &'data Resolution, - venv: &'data Virtualenv, + venv: &'data PythonEnvironment, ) -> impl Future> + Send + 'data { async move { debug!( diff --git a/crates/uv-installer/src/installer.rs b/crates/uv-installer/src/installer.rs index a3b45cfbf..9feaeb013 100644 --- a/crates/uv-installer/src/installer.rs +++ b/crates/uv-installer/src/installer.rs @@ -3,17 +3,17 @@ use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use tracing::instrument; use distribution_types::CachedDist; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; pub struct Installer<'a> { - venv: &'a Virtualenv, + venv: &'a PythonEnvironment, link_mode: install_wheel_rs::linker::LinkMode, reporter: Option>, } impl<'a> Installer<'a> { /// Initialize a new installer. - pub fn new(venv: &'a Virtualenv) -> Self { + pub fn new(venv: &'a PythonEnvironment) -> Self { Self { venv, link_mode: install_wheel_rs::linker::LinkMode::default(), diff --git a/crates/uv-installer/src/plan.rs b/crates/uv-installer/src/plan.rs index 77e269b24..65ef7f55e 100644 --- a/crates/uv-installer/src/plan.rs +++ b/crates/uv-installer/src/plan.rs @@ -16,7 +16,7 @@ use platform_tags::Tags; use uv_cache::{ArchiveTimestamp, Cache, CacheBucket, CacheEntry, Timestamp, WheelCache}; use uv_distribution::{BuiltWheelIndex, RegistryWheelIndex}; use uv_fs::Normalized; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_normalize::PackageName; use uv_traits::NoBinary; @@ -63,7 +63,7 @@ impl<'a> Planner<'a> { no_binary: &NoBinary, index_locations: &IndexLocations, cache: &Cache, - venv: &Virtualenv, + venv: &PythonEnvironment, tags: &Tags, ) -> Result { // Index all the already-downloaded wheels in the cache. diff --git a/crates/uv-installer/src/site_packages.rs b/crates/uv-installer/src/site_packages.rs index 2fe20966f..f83ed8a21 100644 --- a/crates/uv-installer/src/site_packages.rs +++ b/crates/uv-installer/src/site_packages.rs @@ -11,7 +11,7 @@ use distribution_types::{InstalledDist, InstalledMetadata, InstalledVersion, Nam use pep440_rs::{Version, VersionSpecifiers}; use pep508_rs::{Requirement, VerbatimUrl}; use requirements_txt::EditableRequirement; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_normalize::PackageName; use crate::{is_dynamic, not_modified}; @@ -21,7 +21,7 @@ use crate::{is_dynamic, not_modified}; /// Packages are indexed by both name and (for editable installs) URL. #[derive(Debug)] pub struct SitePackages<'a> { - venv: &'a Virtualenv, + venv: &'a PythonEnvironment, /// The vector of all installed distributions. The `by_name` and `by_url` indices index into /// this vector. The vector may contain `None` values, which represent distributions that were /// removed from the virtual environment. @@ -36,7 +36,7 @@ pub struct SitePackages<'a> { impl<'a> SitePackages<'a> { /// Build an index of installed packages from the given Python executable. - pub fn from_executable(venv: &'a Virtualenv) -> Result> { + pub fn from_executable(venv: &'a PythonEnvironment) -> Result> { let mut distributions: Vec> = Vec::new(); let mut by_name = FxHashMap::default(); let mut by_url = FxHashMap::default(); diff --git a/crates/uv-interpreter/src/interpreter.rs b/crates/uv-interpreter/src/interpreter.rs index 8df520e39..2b7086b8a 100644 --- a/crates/uv-interpreter/src/interpreter.rs +++ b/crates/uv-interpreter/src/interpreter.rs @@ -18,15 +18,15 @@ use platform_tags::{Tags, TagsError}; use uv_cache::{Cache, CacheBucket, CachedByTimestamp, Freshness, Timestamp}; use uv_fs::write_atomic_sync; -use crate::python_platform::PythonPlatform; +use crate::python_environment::detect_virtual_env; use crate::python_query::try_find_default_python; -use crate::virtual_env::detect_virtual_env; +use crate::virtualenv_layout::VirtualenvLayout; use crate::{find_requested_python, Error, PythonVersion}; /// A Python executable and its associated platform markers. #[derive(Debug, Clone)] pub struct Interpreter { - platform: PythonPlatform, + platform: Platform, markers: Box, sysconfig_paths: SysconfigPaths, prefix: PathBuf, @@ -48,7 +48,7 @@ impl Interpreter { ); Ok(Self { - platform: PythonPlatform(platform), + platform, markers: Box::new(info.markers), sysconfig_paths: info.sysconfig_paths, prefix: info.prefix, @@ -62,7 +62,7 @@ impl Interpreter { // TODO(konstin): Find a better way mocking the fields pub fn artificial(platform: Platform, markers: MarkerEnvironment) -> Self { Self { - platform: PythonPlatform(platform), + platform, markers: Box::new(markers), sysconfig_paths: SysconfigPaths { stdlib: PathBuf::from("/dev/null"), @@ -85,6 +85,7 @@ impl Interpreter { /// Return a new [`Interpreter`] with the given virtual environment root. #[must_use] pub(crate) fn with_venv_root(self, venv_root: PathBuf) -> Self { + let layout = VirtualenvLayout::from_platform(&self.platform); Self { // Given that we know `venv_root` is a virtualenv, and not an arbitrary Python // interpreter, we can safely assume that the platform is the same as the host @@ -92,20 +93,14 @@ impl Interpreter { // structure, which allows us to avoid querying the interpreter for the `sysconfig` // paths. sysconfig_paths: SysconfigPaths { - purelib: self - .platform - .venv_site_packages(&venv_root, self.python_tuple()), - platlib: self - .platform - .venv_site_packages(&venv_root, self.python_tuple()), - platstdlib: self - .platform - .venv_platstdlib_dir(&venv_root, self.python_tuple()), - scripts: self.platform.venv_scripts_dir(&venv_root), - data: self.platform.venv_data_dir(&venv_root), + purelib: layout.site_packages(&venv_root, self.python_tuple()), + platlib: layout.site_packages(&venv_root, self.python_tuple()), + platstdlib: layout.platstdlib(&venv_root, self.python_tuple()), + scripts: layout.scripts(&venv_root), + data: layout.data(&venv_root), ..self.sysconfig_paths }, - sys_executable: self.platform.venv_python(&venv_root), + sys_executable: layout.python_executable(&venv_root), prefix: venv_root, ..self } @@ -192,10 +187,10 @@ impl Interpreter { }; // Check if the venv Python matches. - let python_platform = PythonPlatform::from(platform.to_owned()); + let python_platform = VirtualenvLayout::from_platform(platform); if let Some(venv) = detect_virtual_env(&python_platform)? { - let executable = python_platform.venv_python(venv); - let interpreter = Self::query(&executable, python_platform.0, cache)?; + let executable = python_platform.python_executable(venv); + let interpreter = Self::query(&executable, platform.clone(), cache)?; if version_matches(&interpreter) { return Ok(Some(interpreter)); diff --git a/crates/uv-interpreter/src/lib.rs b/crates/uv-interpreter/src/lib.rs index 608f3c251..de859f3a2 100644 --- a/crates/uv-interpreter/src/lib.rs +++ b/crates/uv-interpreter/src/lib.rs @@ -6,16 +6,16 @@ use thiserror::Error; pub use crate::cfg::PyVenvConfiguration; pub use crate::interpreter::Interpreter; +pub use crate::python_environment::PythonEnvironment; pub use crate::python_query::{find_default_python, find_requested_python}; pub use crate::python_version::PythonVersion; -pub use crate::virtual_env::Virtualenv; mod cfg; mod interpreter; -mod python_platform; +mod python_environment; mod python_query; mod python_version; -mod virtual_env; +mod virtualenv_layout; #[derive(Debug, Error)] pub enum Error { diff --git a/crates/uv-interpreter/src/virtual_env.rs b/crates/uv-interpreter/src/python_environment.rs similarity index 82% rename from crates/uv-interpreter/src/virtual_env.rs rename to crates/uv-interpreter/src/python_environment.rs index 0998ad71c..559ebce44 100644 --- a/crates/uv-interpreter/src/virtual_env.rs +++ b/crates/uv-interpreter/src/python_environment.rs @@ -8,26 +8,26 @@ use uv_cache::Cache; use uv_fs::{LockedFile, Normalized}; use crate::cfg::PyVenvConfiguration; -use crate::python_platform::PythonPlatform; +use crate::virtualenv_layout::VirtualenvLayout; use crate::{find_default_python, find_requested_python, Error, Interpreter}; -/// A Python executable and its associated platform markers. +/// A Python environment, consisting of a Python [`Interpreter`] and a root directory. #[derive(Debug, Clone)] -pub struct Virtualenv { +pub struct PythonEnvironment { root: PathBuf, interpreter: Interpreter, } -impl Virtualenv { - /// Create a [`Virtualenv`] for an existing virtual environment. - pub fn from_env(platform: Platform, cache: &Cache) -> Result { - let platform = PythonPlatform::from(platform); - let Some(venv) = detect_virtual_env(&platform)? else { +impl PythonEnvironment { + /// Create a [`PythonEnvironment`] for an existing virtual environment. + pub fn from_virtualenv(platform: Platform, cache: &Cache) -> Result { + let layout = VirtualenvLayout::from_platform(&platform); + let Some(venv) = detect_virtual_env(&layout)? else { return Err(Error::VenvNotFound); }; let venv = fs_err::canonicalize(venv)?; - let executable = platform.venv_python(&venv); - let interpreter = Interpreter::query(&executable, platform.0, cache)?; + let executable = layout.python_executable(&venv); + let interpreter = Interpreter::query(&executable, platform, cache)?; debug_assert!( interpreter.base_prefix() == interpreter.base_exec_prefix(), @@ -42,7 +42,7 @@ impl Virtualenv { }) } - /// Create a [`Virtualenv`] for a new virtual environment, created with the given interpreter. + /// Create a [`PythonEnvironment`] for a new virtual environment, created with the given interpreter. pub fn from_interpreter(interpreter: Interpreter, venv: &Path) -> Self { Self { interpreter: interpreter.with_venv_root(venv.to_path_buf()), @@ -50,7 +50,7 @@ impl Virtualenv { } } - /// Create a [`Virtualenv`] for a Python interpreter specifier (e.g., a path or a binary name). + /// Create a [`PythonEnvironment`] for a Python interpreter specifier (e.g., a path or a binary name). pub fn from_requested_python( python: &str, platform: &Platform, @@ -65,7 +65,7 @@ impl Virtualenv { }) } - /// Create a [`Virtualenv`] for the default Python interpreter. + /// Create a [`PythonEnvironment`] for the default Python interpreter. pub fn from_default_python(platform: &Platform, cache: &Cache) -> Result { let interpreter = find_default_python(platform, cache)?; Ok(Self { @@ -112,7 +112,7 @@ impl Virtualenv { } /// Locate the current virtual environment. -pub(crate) fn detect_virtual_env(target: &PythonPlatform) -> Result, Error> { +pub(crate) fn detect_virtual_env(layout: &VirtualenvLayout) -> Result, Error> { match ( env::var_os("VIRTUAL_ENV").filter(|value| !value.is_empty()), env::var_os("CONDA_PREFIX").filter(|value| !value.is_empty()), @@ -148,7 +148,7 @@ pub(crate) fn detect_virtual_env(target: &PythonPlatform) -> Result(&'a Platform); + +impl<'a> VirtualenvLayout<'a> { + /// Create a new [`VirtualenvLayout`] for the given platform. + pub(crate) fn from_platform(platform: &'a Platform) -> Self { + Self(platform) + } -impl PythonPlatform { /// Returns the path to the `python` executable inside a virtual environment. - pub(crate) fn venv_python(&self, venv_root: impl AsRef) -> PathBuf { - self.venv_scripts_dir(venv_root) - .join(format!("python{EXE_SUFFIX}")) + pub(crate) fn python_executable(&self, venv_root: impl AsRef) -> PathBuf { + self.scripts(venv_root).join(format!("python{EXE_SUFFIX}")) } /// Returns the directory in which the binaries are stored inside a virtual environment. - pub(crate) fn venv_scripts_dir(&self, venv_root: impl AsRef) -> PathBuf { + pub(crate) fn scripts(&self, venv_root: impl AsRef) -> PathBuf { let venv = venv_root.as_ref(); if matches!(self.0.os(), Os::Windows) { let bin_dir = venv.join("Scripts"); @@ -38,11 +41,7 @@ impl PythonPlatform { } /// Returns the path to the `site-packages` directory inside a virtual environment. - pub(crate) fn venv_site_packages( - &self, - venv_root: impl AsRef, - version: (u8, u8), - ) -> PathBuf { + pub(crate) fn site_packages(&self, venv_root: impl AsRef, version: (u8, u8)) -> PathBuf { let venv = venv_root.as_ref(); if matches!(self.0.os(), Os::Windows) { venv.join("Lib").join("site-packages") @@ -55,17 +54,13 @@ impl PythonPlatform { /// Returns the path to the `data` directory inside a virtual environment. #[allow(clippy::unused_self)] - pub(crate) fn venv_data_dir(&self, venv_root: impl AsRef) -> PathBuf { + pub(crate) fn data(&self, venv_root: impl AsRef) -> PathBuf { venv_root.as_ref().to_path_buf() } /// Returns the path to the `platstdlib` directory inside a virtual environment. #[allow(clippy::unused_self)] - pub(crate) fn venv_platstdlib_dir( - &self, - venv_root: impl AsRef, - version: (u8, u8), - ) -> PathBuf { + pub(crate) fn platstdlib(&self, venv_root: impl AsRef, version: (u8, u8)) -> PathBuf { let venv = venv_root.as_ref(); if matches!(self.0.os(), Os::Windows) { venv.join("Lib") @@ -76,17 +71,3 @@ impl PythonPlatform { } } } - -impl From for PythonPlatform { - fn from(platform: Platform) -> Self { - Self(platform) - } -} - -impl Deref for PythonPlatform { - type Target = Platform; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} diff --git a/crates/uv-resolver/tests/resolver.rs b/crates/uv-resolver/tests/resolver.rs index 29c533b02..06e6a0569 100644 --- a/crates/uv-resolver/tests/resolver.rs +++ b/crates/uv-resolver/tests/resolver.rs @@ -16,7 +16,7 @@ use platform_host::{Arch, Os, Platform}; use platform_tags::Tags; use uv_cache::Cache; use uv_client::{FlatIndex, RegistryClientBuilder}; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; use uv_resolver::{ DisplayResolutionGraph, InMemoryIndex, Manifest, Options, OptionsBuilder, PreReleaseMode, ResolutionGraph, ResolutionMode, Resolver, @@ -77,7 +77,7 @@ impl BuildContext for DummyContext { panic!("The test should not need to build source distributions") } - async fn install<'a>(&'a self, _: &'a Resolution, _: &'a Virtualenv) -> Result<()> { + async fn install<'a>(&'a self, _: &'a Resolution, _: &'a PythonEnvironment) -> Result<()> { panic!("The test should not need to build source distributions") } diff --git a/crates/uv-traits/src/lib.rs b/crates/uv-traits/src/lib.rs index a0b38732e..5078b4723 100644 --- a/crates/uv-traits/src/lib.rs +++ b/crates/uv-traits/src/lib.rs @@ -14,7 +14,7 @@ use distribution_types::{CachedDist, DistributionId, IndexLocations, Resolution, use once_map::OnceMap; use pep508_rs::Requirement; use uv_cache::Cache; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; use uv_normalize::PackageName; /// Avoid cyclic crate dependencies between resolver, installer and builder. @@ -90,7 +90,7 @@ pub trait BuildContext: Sync { fn install<'a>( &'a self, resolution: &'a Resolution, - venv: &'a Virtualenv, + venv: &'a PythonEnvironment, ) -> impl Future> + Send + 'a; /// Setup a source distribution build by installing the required dependencies. A wrapper for diff --git a/crates/uv/src/commands/pip_freeze.rs b/crates/uv/src/commands/pip_freeze.rs index e8a57c919..6555f4b32 100644 --- a/crates/uv/src/commands/pip_freeze.rs +++ b/crates/uv/src/commands/pip_freeze.rs @@ -11,7 +11,7 @@ use platform_host::Platform; use uv_cache::Cache; use uv_fs::Normalized; use uv_installer::SitePackages; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use crate::commands::ExitStatus; use crate::printer::Printer; @@ -26,12 +26,12 @@ pub(crate) fn pip_freeze( // Detect the current Python interpreter. let platform = Platform::current()?; let venv = if let Some(python) = python { - Virtualenv::from_requested_python(python, &platform, cache)? + PythonEnvironment::from_requested_python(python, &platform, cache)? } else { - match Virtualenv::from_env(platform.clone(), cache) { + match PythonEnvironment::from_virtualenv(platform.clone(), cache) { Ok(venv) => venv, Err(uv_interpreter::Error::VenvNotFound) => { - Virtualenv::from_default_python(&platform, cache)? + PythonEnvironment::from_default_python(&platform, cache)? } Err(err) => return Err(err.into()), } diff --git a/crates/uv/src/commands/pip_install.rs b/crates/uv/src/commands/pip_install.rs index 18d0c0dfa..a58ada202 100644 --- a/crates/uv/src/commands/pip_install.rs +++ b/crates/uv/src/commands/pip_install.rs @@ -26,7 +26,7 @@ use uv_fs::Normalized; use uv_installer::{ BuiltEditable, Downloader, NoBinary, Plan, Planner, Reinstall, ResolvedEditable, SitePackages, }; -use uv_interpreter::{Interpreter, Virtualenv}; +use uv_interpreter::{Interpreter, PythonEnvironment}; use uv_normalize::PackageName; use uv_resolver::{ DependencyMode, InMemoryIndex, Manifest, Options, OptionsBuilder, PreReleaseMode, @@ -106,9 +106,9 @@ pub(crate) async fn pip_install( // Detect the current Python interpreter. let platform = Platform::current()?; let venv = if let Some(python) = python.as_ref() { - Virtualenv::from_requested_python(python, &platform, &cache)? + PythonEnvironment::from_requested_python(python, &platform, &cache)? } else { - Virtualenv::from_env(platform, &cache)? + PythonEnvironment::from_virtualenv(platform, &cache)? }; debug!( "Using Python {} environment at {}", @@ -509,7 +509,7 @@ async fn install( in_flight: &InFlight, build_dispatch: &BuildDispatch<'_>, cache: &Cache, - venv: &Virtualenv, + venv: &PythonEnvironment, mut printer: Printer, ) -> Result<(), Error> { let start = std::time::Instant::now(); @@ -707,7 +707,11 @@ async fn install( } /// Validate the installed packages in the virtual environment. -fn validate(resolution: &Resolution, venv: &Virtualenv, mut printer: Printer) -> Result<(), Error> { +fn validate( + resolution: &Resolution, + venv: &PythonEnvironment, + mut printer: Printer, +) -> Result<(), Error> { let site_packages = SitePackages::from_executable(venv)?; let diagnostics = site_packages.diagnostics()?; for diagnostic in diagnostics { diff --git a/crates/uv/src/commands/pip_list.rs b/crates/uv/src/commands/pip_list.rs index 2f4cc7ce6..47fcdceda 100644 --- a/crates/uv/src/commands/pip_list.rs +++ b/crates/uv/src/commands/pip_list.rs @@ -13,7 +13,7 @@ use platform_host::Platform; use uv_cache::Cache; use uv_fs::Normalized; use uv_installer::SitePackages; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_normalize::PackageName; use crate::commands::ExitStatus; @@ -32,12 +32,12 @@ pub(crate) fn pip_list( // Detect the current Python interpreter. let platform = Platform::current()?; let venv = if let Some(python) = python { - Virtualenv::from_requested_python(python, &platform, cache)? + PythonEnvironment::from_requested_python(python, &platform, cache)? } else { - match Virtualenv::from_env(platform.clone(), cache) { + match PythonEnvironment::from_virtualenv(platform.clone(), cache) { Ok(venv) => venv, Err(uv_interpreter::Error::VenvNotFound) => { - Virtualenv::from_default_python(&platform, cache)? + PythonEnvironment::from_default_python(&platform, cache)? } Err(err) => return Err(err.into()), } diff --git a/crates/uv/src/commands/pip_sync.rs b/crates/uv/src/commands/pip_sync.rs index 39a7f3e66..c8585ff36 100644 --- a/crates/uv/src/commands/pip_sync.rs +++ b/crates/uv/src/commands/pip_sync.rs @@ -19,7 +19,7 @@ use uv_installer::{ is_dynamic, not_modified, Downloader, NoBinary, Plan, Planner, Reinstall, ResolvedEditable, SitePackages, }; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use uv_resolver::InMemoryIndex; use uv_traits::{ConfigSettings, InFlight, NoBuild, SetupPyStrategy}; @@ -74,9 +74,9 @@ pub(crate) async fn pip_sync( // Detect the current Python interpreter. let platform = Platform::current()?; let venv = if let Some(python) = python.as_ref() { - Virtualenv::from_requested_python(python, &platform, &cache)? + PythonEnvironment::from_requested_python(python, &platform, &cache)? } else { - Virtualenv::from_env(platform, &cache)? + PythonEnvironment::from_virtualenv(platform, &cache)? }; debug!( "Using Python {} environment at {}", @@ -406,7 +406,7 @@ async fn resolve_editables( editables: Vec, site_packages: &SitePackages<'_>, reinstall: &Reinstall, - venv: &Virtualenv, + venv: &PythonEnvironment, tags: &Tags, cache: &Cache, client: &RegistryClient, diff --git a/crates/uv/src/commands/pip_uninstall.rs b/crates/uv/src/commands/pip_uninstall.rs index 09e3439a5..85c5fbfcd 100644 --- a/crates/uv/src/commands/pip_uninstall.rs +++ b/crates/uv/src/commands/pip_uninstall.rs @@ -8,7 +8,7 @@ use distribution_types::{InstalledMetadata, Name}; use platform_host::Platform; use uv_cache::Cache; use uv_fs::Normalized; -use uv_interpreter::Virtualenv; +use uv_interpreter::PythonEnvironment; use crate::commands::{elapsed, ExitStatus}; use crate::printer::Printer; @@ -40,9 +40,9 @@ pub(crate) async fn pip_uninstall( // Detect the current Python interpreter. let platform = Platform::current()?; let venv = if let Some(python) = python.as_ref() { - Virtualenv::from_requested_python(python, &platform, &cache)? + PythonEnvironment::from_requested_python(python, &platform, &cache)? } else { - Virtualenv::from_env(platform, &cache)? + PythonEnvironment::from_virtualenv(platform, &cache)? }; debug!( "Using Python {} environment at {}",