From 93dd46c9a22025d607f0596d5f5576f9bc79f389 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Tue, 19 Mar 2024 18:40:19 +0100 Subject: [PATCH] use best_platform in a few places --- src/cli/run.rs | 5 ++++- src/environment.rs | 2 +- src/lock_file/update.rs | 10 ++++++---- src/project/environment.rs | 16 ++++++++++++++++ src/project/virtual_packages.rs | 12 ++++++------ tests/common/mod.rs | 7 +++++-- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/cli/run.rs b/src/cli/run.rs index 3a94da720..b7904a831 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -102,7 +102,10 @@ pub async fn execute(args: Args) -> miette::Result<()> { let search_environment = SearchEnvironments::from_opt_env( &project, explicit_environment.clone(), - Some(Platform::current()), + explicit_environment + .as_ref() + .map(|e| e.best_platform()) + .or(Some(Platform::current())), ) .with_disambiguate_fn(disambiguate_task_interactive); diff --git a/src/environment.rs b/src/environment.rs index 53ca9eb81..596240b56 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -178,7 +178,7 @@ pub async fn get_up_to_date_prefix( mut no_install: bool, existing_repo_data: IndexMap<(Channel, Platform), SparseRepoData>, ) -> miette::Result { - let current_platform = Platform::current(); + let current_platform = environment.best_platform(); let project = environment.project(); // Do not install if the platform is not supported diff --git a/src/lock_file/update.rs b/src/lock_file/update.rs index ba2033abb..a66bb8e6d 100644 --- a/src/lock_file/update.rs +++ b/src/lock_file/update.rs @@ -101,7 +101,7 @@ impl<'p> LockFileDerivedData<'p> { } // Get the prefix with the conda packages installed. - let platform = Platform::current(); + let platform = environment.best_platform(); let (prefix, python_status) = self.conda_prefix(environment).await?; let repodata_records = self .repodata_records(environment, platform) @@ -173,7 +173,7 @@ impl<'p> LockFileDerivedData<'p> { } let prefix = Prefix::new(environment.dir()); - let platform = Platform::current(); + let platform = environment.best_platform(); // Determine the currently installed packages. let installed_packages = prefix @@ -619,7 +619,9 @@ pub async fn ensure_up_to_date_lock_file( // we solve the platforms. We want to solve the current platform first, so we can start // instantiating prefixes if we have to. let mut ordered_platforms = platforms.into_iter().collect::>(); - if let Some(current_platform_index) = ordered_platforms.get_index_of(¤t_platform) { + if let Some(current_platform_index) = + ordered_platforms.get_index_of(&environment.best_platform()) + { ordered_platforms.move_index(current_platform_index, 0); } @@ -704,7 +706,7 @@ pub async fn ensure_up_to_date_lock_file( // Construct a future that will resolve when we have the repodata available for the current // platform for this group. let records_future = context - .get_latest_group_repodata_records(&group, current_platform) + .get_latest_group_repodata_records(&group, environment.best_platform()) .expect("conda records should be available now or in the future"); // Spawn a task to instantiate the environment diff --git a/src/project/environment.rs b/src/project/environment.rs index 1cf04df4b..f1a6e64bd 100644 --- a/src/project/environment.rs +++ b/src/project/environment.rs @@ -187,6 +187,22 @@ impl<'p> Environment<'p> { .unwrap_or_default() } + /// Returns the best platform for the current platform & environment. + pub fn best_platform(&self) -> Platform { + let current = Platform::current(); + + // If the current platform is supported, return it. + if self.platforms().contains(¤t) { + return current; + } + + if current.is_osx() && self.platforms().contains(&Platform::Osx64) { + return Platform::Osx64; + } + + current + } + /// Returns the tasks defined for this environment. /// /// Tasks are defined on a per-target per-feature per-environment basis. diff --git a/src/project/virtual_packages.rs b/src/project/virtual_packages.rs index 2c3f3fbfb..4b5f03c90 100644 --- a/src/project/virtual_packages.rs +++ b/src/project/virtual_packages.rs @@ -69,11 +69,11 @@ pub fn get_minimal_virtual_packages( virtual_packages.push(VirtualPackage::Win); } - if let Some(archspec) = system_requirements.archspec.clone() { - virtual_packages.push(VirtualPackage::Archspec(Archspec { spec: archspec })) - } else if let Some(archspec) = Archspec::from_platform(platform) { - virtual_packages.push(archspec.into()) - } + // if let Some(archspec) = system_requirements.archspec.clone() { + // virtual_packages.push(VirtualPackage::Archspec(Archspec { spec: archspec })) + // } else if let Some(archspec) = Archspec::from_platform(platform) { + // virtual_packages.push(archspec.into()) + // } // Add platform specific packages if platform.is_osx() { @@ -139,7 +139,7 @@ pub enum VerifyCurrentPlatformError { pub fn verify_current_platform_has_required_virtual_packages( environment: &Environment<'_>, ) -> Result<(), VerifyCurrentPlatformError> { - let current_platform = Platform::current(); + let current_platform = environment.best_platform(); // Is the current platform in the list of supported platforms? if !environment.platforms().contains(¤t_platform) { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b9ffa7a86..867bc6328 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -290,8 +290,11 @@ impl PixiControl { // Create a task graph from the command line arguments. let search_env = SearchEnvironments::from_opt_env( &project, - explicit_environment, - Some(Platform::current()), + explicit_environment.clone(), + explicit_environment + .as_ref() + .map(|e| e.best_platform()) + .or(Some(Platform::current())), ); let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task) .map_err(RunError::TaskGraphError)?;