| 1 | use std::time::Duration; |
| 2 | |
| 3 | use codewhale_dependencies::ExternalTool as _; |
| 4 | use codewhale_repl::PythonRuntime; |
| 5 | |
| 6 | use crate::tools::spec::ToolContext; |
| 7 | |
| 8 | const NO_INTERPRETER: &str = "no Python interpreter found on PATH (tried python3, python, py -3). \ |
| 9 | Install Python 3 and restart codewhale."; |
| 10 | |
| 11 | pub(crate) async fn spawn_kernel( |
| 12 | tool_context: &ToolContext, |
| 13 | context: Option<&str>, |
| 14 | round_timeout: Option<Duration>, |
| 15 | ) -> Result<PythonRuntime, String> { |
| 16 | let interpreter = codewhale_dependencies::Python::resolve().ok_or(NO_INTERPRETER)?; |
| 17 | let (program, fixed_args) = codewhale_dependencies::split_interpreter_spec(&interpreter); |
| 18 | PythonRuntime::spawn(context, round_timeout, |kernel_args| { |
| 19 | let mut args = fixed_args; |
| 20 | args.extend(kernel_args); |
| 21 | crate::tools::shell::sandboxed_runner_command( |
| 22 | tool_context, |
| 23 | &program, |
| 24 | args, |
| 25 | &tool_context.workspace, |
| 26 | codewhale_repl::INLINE_ROUND_TIMEOUT, |
| 27 | ) |
| 28 | .map_err(|error| error.to_string()) |
| 29 | }) |
| 30 | .await |
| 31 | } |
| 32 |