Skip to content

Commit

Permalink
Eim 22 python path (#38)
Browse files Browse the repository at this point in the history
* sanity recheck after python instalation added

* added recheck for cases when default windows non-python is faultly detected

---------

Co-authored-by: Petr Gadorek <[email protected]>
  • Loading branch information
Hahihula and Petr Gadorek authored Sep 5, 2024
1 parent 8202c09 commit 62f430e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions src/wizard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions src/wizard/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand Down

0 comments on commit 62f430e

Please sign in to comment.