MCPcopy Create free account
hub / github.com/Glyphack/enderpy / spawn_python_script_command

Function spawn_python_script_command

compat/src/runpython.rs:6–30  ·  view source on GitHub ↗
(
    script_path: S,
    args: Vec<&str>,
    python_path: P,
)

Source from the content-addressed store, hash-verified

4use which::which;
5
6pub fn spawn_python_script_command<S, P>(
7 script_path: S,
8 args: Vec<&str>,
9 python_path: P,
10) -> Result<Child>
11where
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
32fn enderpy_root_path() -> Result<PathBuf> {
33 let mut path = std::env::current_exe().into_diagnostic()?;

Callers 2

parse_python_sourceFunction · 0.85
lex_python_sourceFunction · 0.85

Calls 1

enderpy_root_pathFunction · 0.85

Tested by

no test coverage detected