(
script_path: S,
args: Vec<&str>,
python_path: P,
)
| 4 | use which::which; |
| 5 | |
| 6 | pub fn spawn_python_script_command<S, P>( |
| 7 | script_path: S, |
| 8 | args: Vec<&str>, |
| 9 | python_path: P, |
| 10 | ) -> Result<Child> |
| 11 | where |
| 12 | S: AsRef<Path>, |
| 13 | P: AsRef<Path>, |
| 14 | { |
| 15 | let script_path = if script_path.as_ref().is_relative() { |
| 16 | let enderpy_dir = enderpy_root_path()?; |
| 17 | enderpy_dir.join(script_path) |
| 18 | } else { |
| 19 | script_path.as_ref().to_path_buf() |
| 20 | }; |
| 21 | script_path.try_exists().into_diagnostic()?; |
| 22 | |
| 23 | Command::new(python_path.as_ref()) |
| 24 | .arg(&script_path) |
| 25 | .args(args) |
| 26 | .stdin(Stdio::piped()) |
| 27 | .stdout(Stdio::piped()) |
| 28 | .spawn() |
| 29 | .into_diagnostic() |
| 30 | } |
| 31 | |
| 32 | fn enderpy_root_path() -> Result<PathBuf> { |
| 33 | let mut path = std::env::current_exe().into_diagnostic()?; |
no test coverage detected