From 1cce968acd064ec26baf1ce3d6e068c39e3ce694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Mon, 15 Jan 2024 17:10:29 +0300 Subject: [PATCH] refactor: automate --no-install behavior --- src/environment.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/environment.rs b/src/environment.rs index 2c3b0faa1..8f7c0cad7 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -2,7 +2,7 @@ use crate::{ consts, default_authenticated_client, install, install_pypi, lock_file, prefix::Prefix, progress, Project, }; -use miette::{Context, IntoDiagnostic, LabeledSpan}; +use miette::{Context, IntoDiagnostic}; use crate::lock_file::lock_file_satisfies_project; use crate::project::virtual_packages::verify_current_platform_has_required_virtual_packages; @@ -57,29 +57,15 @@ fn create_prefix_location_file(prefix_file: &Path) -> miette::Result<()> { /// 1. It verifies that the prefix location is unchanged. /// 2. It verifies that the project supports the current platform. /// 3. It verifies that the system requirements are met. -pub fn sanity_check_project(project: &Project, no_install: bool) -> miette::Result<()> { +pub fn sanity_check_project(project: &Project, no_install: &mut bool) -> miette::Result<()> { // Sanity check of prefix location verify_prefix_location_unchanged(project.pixi_dir().join(consts::PREFIX_FILE_NAME).as_path())?; // Make sure the project supports the current platform let platform = Platform::current(); if !project.platforms().contains(&platform) { - let span = project.manifest.parsed.project.platforms.span(); - if no_install { - tracing::warn!("Adding dependency for unsupported platform ({platform}).") - } else { - return Err(miette::miette!( - help = format!( - "The project needs to be configured to support your platform ({platform})." - ), - labels = vec![LabeledSpan::at( - span.unwrap_or_default(), - format!("add '{platform}' here"), - )], - "the project is not configured for your current platform" - ) - .with_source_code(project.manifest_named_source())); - }; + *no_install = true; + tracing::warn!("Adding dependency for unsupported platform ({platform}).") } // Make sure the system requirements are met @@ -128,11 +114,11 @@ impl LockFileUsage { pub async fn get_up_to_date_prefix( project: &Project, usage: LockFileUsage, - no_install: bool, + mut no_install: bool, sparse_repo_data: Option>, ) -> miette::Result { // Make sure the project is in a sane state - sanity_check_project(project, no_install)?; + sanity_check_project(project, &mut no_install)?; // Start loading the installed packages in the background let prefix = Prefix::new(project.environment_dir())?;