From 62f430ea92b66f35085e0d5470ab20edc500987c Mon Sep 17 00:00:00 2001 From: Hahihula Date: Thu, 5 Sep 2024 09:20:28 +0200 Subject: [PATCH] Eim 22 python path (#38) * sanity recheck after python instalation added * added recheck for cases when default windows non-python is faultly detected --------- Co-authored-by: Petr Gadorek --- Cargo.lock | 2 +- src/wizard/mod.rs | 26 +++++++++++++++++++++++--- src/wizard/prompts.rs | 24 ++++++++++++++++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf6b9bb..f6b2efd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1853,7 +1853,7 @@ dependencies = [ [[package]] name = "idf-im-lib" version = "0.1.0" -source = "git+https://github.com/espressif/idf-im-lib.git?branch=master#d7d809c9ebf11098d343b1648692a78f4d4eb525" +source = "git+https://github.com/espressif/idf-im-lib.git?branch=master#bac7610978aca588bdf036a03394e806a3b718d1" dependencies = [ "colored", "decompress", diff --git a/src/wizard/mod.rs b/src/wizard/mod.rs index 3ed6771..5cd0d0a 100644 --- a/src/wizard/mod.rs +++ b/src/wizard/mod.rs @@ -68,10 +68,30 @@ async fn download_tools( ); let list = idf_im_lib::idf_tools::filter_tools_by_target(tools_file.tools, &selected_chip); - let platform = match idf_im_lib::idf_tools::get_platform_identification() { + let platform = match idf_im_lib::idf_tools::get_platform_identification(None) { Ok(platform) => platform, Err(err) => { - panic!("{}. {:?}", t!("wizard.tools_platform_error"), err); + if std::env::consts::OS == "windows" { + // All this is for cases when on windows microsoft store creates "pseudolinks" for python + let scp = idf_im_lib::system_dependencies::get_scoop_path(); + let usable_python = match scp { + Some(path) => { + let mut python_path = PathBuf::from(path); + python_path.push("python3.exe"); + python_path.to_str().unwrap().to_string() + } + None => "python3.exe".to_string(), + }; + match idf_im_lib::idf_tools::get_platform_identification(Some(&usable_python)) { + Ok(platform) => platform, + Err(err) => { + error!("Unable to identify platform: {}", err); + panic!("{}. {:?}", t!("wizard.tools_platform_error"), err); + } + } + } else { + panic!("{}. {:?}", t!("wizard.tools_platform_error"), err); + } } }; debug!("Python platform: {}", platform); @@ -570,7 +590,7 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> { version_instalation_path.push(&idf_version); let mut idf_path = version_instalation_path.clone(); idf_path.push("esp-idf"); - config.idf_path = Some(idf_path.clone()); // TODO: handle multiple versions + config.idf_path = Some(idf_path.clone()); idf_im_lib::add_path_to_path(idf_path.to_str().unwrap()); // download idf diff --git a/src/wizard/prompts.rs b/src/wizard/prompts.rs index 9894be9..a091522 100644 --- a/src/wizard/prompts.rs +++ b/src/wizard/prompts.rs @@ -81,8 +81,8 @@ pub fn check_and_install_prerequisites() -> Result<(), String> { Ok(()) } -fn python_sanity_check() -> Result<(), String> { - let outpusts = idf_im_lib::python_utils::python_sanity_check(None); +fn python_sanity_check(python: Option<&str>) -> Result<(), String> { + let outpusts = idf_im_lib::python_utils::python_sanity_check(python); let mut all_ok = true; for output in outpusts { match output { @@ -102,13 +102,29 @@ fn python_sanity_check() -> Result<(), String> { } pub fn check_and_install_python() -> Result<(), String> { info!("{}", t!("python.sanitycheck.info")); - if let Err(err) = run_with_spinner(python_sanity_check) { + if let Err(err) = run_with_spinner(|| python_sanity_check(None)) { if std::env::consts::OS == "windows" { info!("{}", t!("python.sanitycheck.fail")); if generic_confirm("pythhon.install.prompt").map_err(|e| e.to_string())? { system_dependencies::install_prerequisites(vec!["python".to_string()]) .map_err(|e| e.to_string())?; - info!("{}", t!("python.install.success")); + let scp = system_dependencies::get_scoop_path(); + let usable_python = match scp { + Some(path) => { + let mut python_path = PathBuf::from(path); + python_path.push("python3.exe"); + python_path + .to_str() + .map(|s| s.to_string()) + .ok_or_else(|| "Unable to convert path to string".to_string())? + } + None => "python3.exe".to_string(), + }; + debug!("Using Python: {}", usable_python); + match run_with_spinner(|| python_sanity_check(Some(&usable_python))) { + Ok(_) => info!("{}", t!("python.install.success")), + Err(err) => return Err(format!("{} {:?}", t!("python.install.failure"), err)), + } } else { return Err(t!("python.install.refuse").to_string()); }