Skip to content

Commit d26907d

Browse files
committed
reimplement idf_tools.py install-python-env
1 parent 6ed5aa0 commit d26907d

File tree

7 files changed

+553
-149
lines changed

7 files changed

+553
-149
lines changed

src-tauri/src/cli/wizard.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async fn download_tools(
132132
})
133133
};
134134

135-
match idf_im_lib::download_file(&download_link.url, destination_path, progress_tx).await {
135+
match idf_im_lib::download_file(&download_link.url, destination_path, Some(progress_tx)).await {
136136
Ok(_) => {
137137
downloaded_tools.push(filename.to_string());
138138
progress_bar.finish();
@@ -577,29 +577,24 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
577577
&tool_install_directory,
578578
)
579579
.await?;
580-
let parent_tools = tool_install_directory.parent().unwrap();
581-
let env_vars =
582-
idf_im_lib::setup_environment_variables(&parent_tools.to_path_buf(), &idf_path)?;
583-
let real_env_vars = idf_im_lib::setup_environment_variables(
584-
&tool_install_directory.to_path_buf(),
585-
&idf_path,
586-
)?;
587-
let idf_tools_path = get_and_validate_idf_tools_path(&mut config, &idf_path)?;
588-
if config.idf_features.is_some() {
589-
let features = config.idf_features.clone().unwrap();
590-
idf_im_lib::python_utils::run_idf_tools_py_with_features(
591-
idf_tools_path.to_str().unwrap(),
592-
&env_vars,
593-
&real_env_vars,
594-
&features,
595-
)?;
596-
} else {
597-
idf_im_lib::python_utils::run_idf_tools_py(
598-
idf_tools_path.to_str().unwrap(),
599-
&env_vars,
600-
&real_env_vars,
601-
)?;
602-
}
580+
match idf_im_lib::python_utils::install_python_env(
581+
&idf_version,
582+
&tool_install_directory,
583+
true, //TODO: actually read from config
584+
&idf_path,
585+
&config.idf_features.clone().unwrap_or_default(),
586+
).await {
587+
Ok(_) => {
588+
info!("Python environment installed");
589+
}
590+
Err(err) => {
591+
error!("Failed to install Python environment: {}", err);
592+
return Err(err.to_string());
593+
}
594+
};
595+
let idf_python_env_path = tool_install_directory.join("python").join(&idf_version).join("venv"); //todo: move to config
596+
ensure_path(idf_python_env_path.to_str().unwrap())
597+
.map_err(|err| format!("Failed to create Python environment directory: {}", err))?;
603598

604599
let export_paths = idf_im_lib::idf_tools::get_tools_export_paths(
605600
tools,
@@ -615,13 +610,13 @@ pub async fn run_wizzard_run(mut config: Settings) -> Result<(), String> {
615610
}
616611
})
617612
.collect();
618-
619613
idf_im_lib::single_version_post_install(
620614
version_instalation_path.to_str().unwrap(),
621615
idf_path.to_str().unwrap(),
622616
&idf_version,
623617
tool_install_directory.to_str().unwrap(),
624618
export_paths,
619+
idf_python_env_path.to_str(),
625620
)
626621
}
627622
save_config_if_desired(&config)?;

src-tauri/src/gui/commands/idf_tools.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub async fn setup_tools(
9595
app_handle: &AppHandle,
9696
settings: &Settings,
9797
idf_path: &PathBuf,
98+
idf_version: &str,
9899
) -> Result<Vec<String>> {
99100
info!("Setting up tools...");
100101

@@ -173,19 +174,31 @@ pub async fn setup_tools(
173174
return Err(anyhow!("Failed to setup environment variables: IDF tools path does not exist"));
174175
}
175176

176-
// Run IDF tools Python script
177-
run_idf_tools_py(
178-
idf_tools_path.to_str().unwrap(),
179-
&env_vars_install,
180-
&env_vars_python
181-
).map_err(|e| {
182-
send_message(
177+
match idf_im_lib::python_utils::install_python_env(
178+
&idf_version,
179+
&tools_install_folder,
180+
true, //TODO: actually read from config
181+
&idf_path,
182+
&settings.idf_features.clone().unwrap_or_default(),
183+
).await {
184+
Ok(_) => {
185+
info!("Python environment installed");
186+
send_message(
183187
app_handle,
184-
format!("Failed to run IDF tools setup: {}", e),
185-
"error".to_string(),
186-
);
187-
anyhow!("Failed to run IDF tools setup: {}", e)
188-
})?;
188+
"Python environment installed successfully".to_string(),
189+
"info".to_string(),
190+
);
191+
}
192+
Err(err) => {
193+
error!("Failed to install Python environment: {}", err);
194+
send_message(
195+
app_handle,
196+
"Failed to install Python environment".to_string(),
197+
"error".to_string(),
198+
);
199+
return Err(anyhow!("Failed to install Python environment: {}", err));
200+
}
201+
};
189202

190203
send_message(
191204
app_handle,
@@ -259,7 +272,7 @@ async fn process_tool_download(
259272

260273
// Download file
261274
info!("Downloading {} to: {}", tool_name, full_path_str);
262-
match download_file(&download.url, &tool_setup.download_dir, progress_tx).await {
275+
match download_file(&download.url, &tool_setup.download_dir, Some(progress_tx)).await {
263276
Ok(_) => {
264277
send_tools_message(app_handle, filename.to_string(), "downloaded".to_string());
265278
send_message(

src-tauri/src/gui/commands/installation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async fn install_single_version(
148148

149149
download_idf(&app_handle, settings, &version, &idf_path).await?;
150150

151-
let export_vars = setup_tools(&app_handle, settings, &idf_path).await?;
151+
let export_vars = setup_tools(&app_handle, settings, &idf_path, &version).await?;
152152

153153
let tools_install_path = version_path.clone().join(
154154
settings
@@ -157,12 +157,14 @@ async fn install_single_version(
157157
.unwrap_or_default(),
158158
);
159159

160+
let idf_python_env_path = tools_install_path.clone().join("python").join(&version).join("venv");
160161
idf_im_lib::single_version_post_install(
161162
version_path.to_str().unwrap(),
162163
idf_path.to_str().unwrap(),
163164
&version,
164165
tools_install_path.to_str().unwrap(),
165166
export_vars,
167+
Some(idf_python_env_path.to_str().unwrap()),
166168
);
167169

168170
Ok(())

src-tauri/src/gui/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,21 @@ async fn install_single_version(
211211
let version_path = prepare_installation_directories(app_handle.clone(), settings, &version)?;
212212
let idf_path = version_path.clone().join("esp-idf");
213213
download_idf(&app_handle, settings, &version, &idf_path).await?;
214-
let export_vars = setup_tools(&app_handle, settings, &idf_path).await?;
214+
let export_vars = setup_tools(&app_handle, settings, &idf_path, &version).await?;
215215
let tools_install_path = version_path.clone().join(
216216
settings
217217
.tool_install_folder_name
218218
.clone()
219219
.unwrap_or_default(),
220220
);
221+
let idf_python_env_path = tools_install_path.clone().join("python").join(&version).join("venv");
221222
idf_im_lib::single_version_post_install(
222223
version_path.to_str().unwrap(),
223224
idf_path.to_str().unwrap(),
224225
&version,
225226
tools_install_path.to_str().unwrap(),
226227
export_vars,
228+
Some(idf_python_env_path.to_str().unwrap()),
227229
);
228230

229231
Ok(())

0 commit comments

Comments
 (0)