diff --git a/crates/rattler_installs_packages/src/artifacts/sdist.rs b/crates/rattler_installs_packages/src/artifacts/sdist.rs index 88287271..23ca0164 100644 --- a/crates/rattler_installs_packages/src/artifacts/sdist.rs +++ b/crates/rattler_installs_packages/src/artifacts/sdist.rs @@ -191,7 +191,7 @@ fn generic_archive_reader( #[cfg(test)] mod tests { use crate::artifacts::SDist; - use crate::python_env::Pep508EnvMakers; + use crate::python_env::{Pep508EnvMakers, PythonLocation}; use crate::wheel_builder::WheelBuilder; use crate::{index::PackageDb, resolve::ResolveOptions}; use insta::{assert_debug_snapshot, assert_ron_snapshot}; @@ -261,6 +261,7 @@ mod tests { None, &resolve_options, package_db.1.path(), + PythonLocation::System, ); let result = wheel_builder.get_sdist_metadata(&sdist).await.unwrap(); @@ -284,6 +285,7 @@ mod tests { None, &resolve_options, package_db.1.path(), + PythonLocation::System, ); // Build the wheel @@ -309,6 +311,7 @@ mod tests { None, &resolve_options, package_db.1.path(), + PythonLocation::System, ); // Build the wheel diff --git a/crates/rattler_installs_packages/src/python_env/mod.rs b/crates/rattler_installs_packages/src/python_env/mod.rs index 36efe60a..42629614 100644 --- a/crates/rattler_installs_packages/src/python_env/mod.rs +++ b/crates/rattler_installs_packages/src/python_env/mod.rs @@ -24,4 +24,4 @@ pub(crate) use system_python::{ PythonInterpreterVersion, }; pub use uninstall::{uninstall_distribution, UninstallDistributionError}; -pub use venv::{PythonLocation, VEnv}; +pub use venv::{PythonLocation, VEnv, VEnvError}; diff --git a/crates/rattler_installs_packages/src/python_env/venv.rs b/crates/rattler_installs_packages/src/python_env/venv.rs index 9b979c94..b77a1e03 100644 --- a/crates/rattler_installs_packages/src/python_env/venv.rs +++ b/crates/rattler_installs_packages/src/python_env/venv.rs @@ -32,6 +32,7 @@ impl PythonLocation { } } +#[allow(missing_docs)] #[derive(Error, Debug)] pub enum VEnvError { #[error(transparent)] diff --git a/crates/rattler_installs_packages/src/resolve/dependency_provider.rs b/crates/rattler_installs_packages/src/resolve/dependency_provider.rs index d9f53dfc..cb2e03e8 100644 --- a/crates/rattler_installs_packages/src/resolve/dependency_provider.rs +++ b/crates/rattler_installs_packages/src/resolve/dependency_provider.rs @@ -2,7 +2,7 @@ use super::SDistResolution; use crate::artifacts::SDist; use crate::artifacts::Wheel; use crate::index::PackageDb; -use crate::python_env::WheelTags; +use crate::python_env::{PythonLocation, WheelTags}; use crate::resolve::{PinnedPackage, ResolveOptions}; use crate::types::{ Artifact, ArtifactInfo, ArtifactName, Extra, NormalizedPackageName, PackageName, @@ -140,6 +140,7 @@ impl<'db, 'i> PypiDependencyProvider<'db, 'i> { locked_packages: HashMap>, favored_packages: HashMap>, options: &'i ResolveOptions, + python_location: PythonLocation, ) -> miette::Result { let wheel_builder = WheelBuilder::new( package_db, @@ -147,6 +148,7 @@ impl<'db, 'i> PypiDependencyProvider<'db, 'i> { compatible_tags, options, package_db.cache_dir(), + python_location, ); Ok(Self { diff --git a/crates/rattler_installs_packages/src/resolve/solve.rs b/crates/rattler_installs_packages/src/resolve/solve.rs index ddd8071a..6e4d876c 100644 --- a/crates/rattler_installs_packages/src/resolve/solve.rs +++ b/crates/rattler_installs_packages/src/resolve/solve.rs @@ -1,6 +1,6 @@ use super::dependency_provider::PypiPackageName; use crate::index::PackageDb; -use crate::python_env::WheelTags; +use crate::python_env::{PythonLocation, WheelTags}; use crate::resolve::dependency_provider::{PypiDependencyProvider, PypiVersion}; use crate::types::PackageName; use crate::{types::ArtifactInfo, types::Extra, types::NormalizedPackageName, types::Version}; @@ -157,7 +157,9 @@ pub struct ResolveOptions { /// /// If `compatible_tags` is defined then the available artifacts of a distribution are filtered to /// include only artifacts that are compatible with the specified tags. If `None` is passed, the -/// artifacts are not filtered at all. +/// artifacts are not filtered at all +// TODO: refactor this into an input type of sorts later +#[allow(clippy::too_many_arguments)] pub async fn resolve<'db>( package_db: &'db PackageDb, requirements: impl IntoIterator, @@ -166,6 +168,7 @@ pub async fn resolve<'db>( locked_packages: HashMap>, favored_packages: HashMap>, options: &ResolveOptions, + python_location: PythonLocation, ) -> miette::Result>> { // Construct a provider let provider = PypiDependencyProvider::new( @@ -175,6 +178,7 @@ pub async fn resolve<'db>( locked_packages, favored_packages, options, + python_location, )?; let pool = &provider.pool; diff --git a/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs b/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs index 24ca33d9..d992f6bd 100644 --- a/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs +++ b/crates/rattler_installs_packages/src/wheel_builder/build_environment.rs @@ -26,6 +26,7 @@ pub(crate) struct BuildEnvironment<'db> { build_requirements: Vec, resolved_wheels: Vec>, venv: VEnv, + python_location: PythonLocation, } impl<'db> BuildEnvironment<'db> { @@ -105,6 +106,7 @@ impl<'db> BuildEnvironment<'db> { locked_packages, favored_packages, resolve_options, + self.python_location.clone(), ) .await .map_err(|_| WheelBuildError::CouldNotResolveEnvironment(all_requirements))?; @@ -152,10 +154,11 @@ impl<'db> BuildEnvironment<'db> { env_markers: &MarkerEnvironment, wheel_tags: Option<&WheelTags>, resolve_options: &ResolveOptions, + python_location: PythonLocation, ) -> Result, WheelBuildError> { // Setup a work directory and a new env dir let work_dir = tempfile::tempdir().unwrap(); - let venv = VEnv::create(&work_dir.path().join("venv"), PythonLocation::System).unwrap(); + let venv = VEnv::create(&work_dir.path().join("venv"), python_location.clone())?; // Find the build system let build_system = @@ -184,6 +187,7 @@ impl<'db> BuildEnvironment<'db> { HashMap::default(), HashMap::default(), resolve_options, + python_location.clone(), ) .await .map_err(|_| WheelBuildError::CouldNotResolveEnvironment(build_requirements.to_vec()))?; @@ -228,6 +232,7 @@ impl<'db> BuildEnvironment<'db> { entry_point, resolved_wheels, venv, + python_location, }) } } diff --git a/crates/rattler_installs_packages/src/wheel_builder/mod.rs b/crates/rattler_installs_packages/src/wheel_builder/mod.rs index 77290f8b..d8fb6c56 100644 --- a/crates/rattler_installs_packages/src/wheel_builder/mod.rs +++ b/crates/rattler_installs_packages/src/wheel_builder/mod.rs @@ -11,6 +11,7 @@ use std::{collections::HashMap, path::PathBuf}; use parking_lot::Mutex; use pep508_rs::{MarkerEnvironment, Requirement}; +use crate::python_env::{PythonLocation, VEnvError}; use crate::resolve::{ResolveOptions, SDistResolution}; use crate::types::{NormalizedPackageName, ParseArtifactNameError, WheelFilename}; use crate::wheel_builder::build_environment::BuildEnvironment; @@ -49,6 +50,9 @@ pub struct WheelBuilder<'db, 'i> { /// Cache of locally built wheels on the system locally_built_wheels: WheelCache, + + /// Location of the python interpreter to use + python_location: PythonLocation, } /// An error that can occur while building a wheel @@ -84,6 +88,9 @@ pub enum WheelBuildError { #[error("error parsing artifact name: {0}")] ArtifactError(#[from] ParseArtifactNameError), + + #[error("error creating venv: {0}")] + VEnvError(#[from] VEnvError), } impl TryFrom<&SDist> for WheelKey { @@ -125,6 +132,7 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { wheel_tags: Option<&'i WheelTags>, resolve_options: &'i ResolveOptions, wheel_cache_dir: &Path, + python_location: PythonLocation, ) -> Self { // We are running into a chicken & egg problem if we want to build wheels for packages that // require their build system as sdist as well. For example, `hatchling` requires `hatchling` as @@ -146,6 +154,7 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { wheel_tags, resolve_options, locally_built_wheels: WheelCache::new(wheel_cache_dir.to_path_buf()), + python_location, } } @@ -163,7 +172,6 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { return Ok(venv.clone()); } - // If not in cache, create a new one tracing::debug!( "creating virtual env for: {:?}", sdist.name().distribution.as_source_str() @@ -175,6 +183,7 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { self.env_markers, self.wheel_tags, &self.resolve_options, + self.python_location.clone(), ) .await?; @@ -312,7 +321,7 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { mod tests { use crate::artifacts::SDist; use crate::index::PackageDb; - use crate::python_env::Pep508EnvMakers; + use crate::python_env::{Pep508EnvMakers, PythonLocation}; use crate::resolve::ResolveOptions; use crate::wheel_builder::wheel_cache::WheelKey; use crate::wheel_builder::WheelBuilder; @@ -348,6 +357,7 @@ mod tests { None, &resolve_options, package_db.1.path(), + PythonLocation::System, ); // Build the wheel diff --git a/crates/rip_bin/src/main.rs b/crates/rip_bin/src/main.rs index f400f7c6..d6705acf 100644 --- a/crates/rip_bin/src/main.rs +++ b/crates/rip_bin/src/main.rs @@ -140,6 +140,7 @@ async fn actual_main() -> miette::Result<()> { HashMap::default(), HashMap::default(), &resolve_opts, + PythonLocation::System, ) .await { @@ -200,6 +201,7 @@ async fn actual_main() -> miette::Result<()> { Some(&compatible_tags), &resolve_opts, package_db.cache_dir(), + PythonLocation::System, ); for pinned_package in blueprint.into_iter().sorted_by(|a, b| a.name.cmp(&b.name)) {