Skip to content

Commit 32929fa

Browse files
committed
fix: Run fixes for windows
Signed-off-by: Nick Mitchell <[email protected]>
1 parent bc2a82a commit 32929fa

File tree

1 file changed

+54
-16
lines changed
  • pdl-live-react/src-tauri/src/cli

1 file changed

+54
-16
lines changed

pdl-live-react/src-tauri/src/cli/run.rs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ fn pip_install_if_needed(app_handle: tauri::AppHandle) -> Result<String, tauri::
1111

1212
create_dir_all(&cache_path)?;
1313
let venv_path = cache_path.join("interpreter-python");
14-
let activate_path = venv_path
15-
.join("bin/activate")
16-
.into_os_string()
17-
.into_string()
18-
.unwrap();
14+
let activate_path0 = if cfg!(windows) {
15+
venv_path.join("Scripts").join("Activate.ps1")
16+
} else {
17+
venv_path.join("bin/activate")
18+
};
19+
let activate_path = activate_path0.into_os_string().into_string().unwrap();
1920
let cached_requirements_path = venv_path
2021
.join("requirements.txt")
2122
.into_os_string()
@@ -29,7 +30,12 @@ fn pip_install_if_needed(app_handle: tauri::AppHandle) -> Result<String, tauri::
2930
if !venv_path.exists() {
3031
println!("Creating virtual environment...");
3132
let venv_path_string = venv_path.into_os_string().into_string().unwrap();
32-
cmd!("python3.12", "-mvenv", venv_path_string.as_str()).run()?;
33+
let python = if cfg!(target_os = "macos") {
34+
"python3.12"
35+
} else {
36+
"python3"
37+
};
38+
cmd!(python, "-mvenv", venv_path_string.as_str()).run()?;
3339
}
3440

3541
let requirements_path = app_handle
@@ -43,15 +49,43 @@ fn pip_install_if_needed(app_handle: tauri::AppHandle) -> Result<String, tauri::
4349
requirements_path.as_str(),
4450
cached_requirements_path.as_str(),
4551
) {
46-
println!("Running pip install...");
52+
println!(
53+
"Running pip install... {:?}",
54+
if cfg!(windows) {
55+
format!(
56+
"{activate} ; pip install -r '{requirements}'",
57+
activate = activate_path,
58+
requirements = requirements_path
59+
)
60+
} else {
61+
format!(
62+
"source '{activate}' && pip install -r '{requirements}'",
63+
activate = activate_path,
64+
requirements = requirements_path
65+
)
66+
}
67+
.as_str(),
68+
);
4769
cmd!(
48-
"sh",
49-
"-c",
50-
format!(
51-
"source '{activate}' && pip install -r '{requirements}'",
52-
activate = activate_path,
53-
requirements = requirements_path
54-
)
70+
if cfg!(windows) { "powershell" } else { "sh" },
71+
if cfg!(windows) {
72+
"invoke-expression"
73+
} else {
74+
"-c"
75+
},
76+
if cfg!(windows) {
77+
format!(
78+
"{activate} ; pip install -r '{requirements}'",
79+
activate = activate_path,
80+
requirements = requirements_path
81+
)
82+
} else {
83+
format!(
84+
"source '{activate}' && pip install -r '{requirements}'",
85+
activate = activate_path,
86+
requirements = requirements_path
87+
)
88+
}
5589
.as_str(),
5690
)
5791
.run()?;
@@ -103,8 +137,12 @@ pub fn run_pdl_program(
103137
};
104138

105139
cmd!(
106-
"sh",
107-
"-c",
140+
if cfg!(windows) { "powershell" } else { "sh" },
141+
if cfg!(windows) {
142+
"invoke-expression"
143+
} else {
144+
"-c"
145+
},
108146
&[
109147
"source",
110148
activate.as_str(),

0 commit comments

Comments
 (0)