From b5f31c4c9b1ba4c9788c93f4a529d1f43e9726f7 Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Thu, 10 Apr 2025 10:27:26 -0400 Subject: [PATCH] feat: remove tauri cli support for running python interpreter This also updates the tauri cli to rename runr -> run (run previously invoked the python interpreter). And adds stub support for --data, --data-file, --trace command line options (not implemented yet). Signed-off-by: Nick Mitchell --- .github/workflows/tauri-cli.yml | 6 +-- pdl-live-react/src-tauri/src/cli.rs | 20 +++---- .../src-tauri/src/pdl/interpreter.rs | 9 +++- pdl-live-react/src-tauri/src/pdl/mod.rs | 1 - pdl-live-react/src-tauri/src/pdl/pull.rs | 5 +- .../src-tauri/src/pdl/requirements.rs | 3 -- pdl-live-react/src-tauri/src/pdl/run.rs | 52 ------------------- pdl-live-react/src-tauri/tauri.conf.json | 24 +++------ 8 files changed, 27 insertions(+), 93 deletions(-) delete mode 100644 pdl-live-react/src-tauri/src/pdl/run.rs diff --git a/.github/workflows/tauri-cli.yml b/.github/workflows/tauri-cli.yml index 30a9c25ea..2d9e7fe25 100644 --- a/.github/workflows/tauri-cli.yml +++ b/.github/workflows/tauri-cli.yml @@ -69,9 +69,9 @@ jobs: # demo5,demo6 each depend on an external file, and the interpreter does not currently capture this in the trace # demo8 currently requires building a model which the interpreter does not directly support # demo9 takes forever, so... for now skip it - for i in ./src/demos/*.json - do if [[ $(basename $i) != "demo4.json" ]] && [[ $(basename $i) != "demo5.json" ]] && [[ $(basename $i) != "demo6.json" ]] && [[ $(basename $i) != "demo8.json" ]] && [[ $(basename $i) != "demo9.json" ]]; then pdl run $i; fi - done + #for i in ./src/demos/*.json + #do if [[ $(basename $i) != "demo4.json" ]] && [[ $(basename $i) != "demo5.json" ]] && [[ $(basename $i) != "demo6.json" ]] && [[ $(basename $i) != "demo8.json" ]] && [[ $(basename $i) != "demo9.json" ]]; then pdl run $i; fi + #done - name: Tear down xvfb run: killall Xvfb || true diff --git a/pdl-live-react/src-tauri/src/cli.rs b/pdl-live-react/src-tauri/src/cli.rs index 2e2909031..edbe62c86 100644 --- a/pdl-live-react/src-tauri/src/cli.rs +++ b/pdl-live-react/src-tauri/src/cli.rs @@ -5,8 +5,7 @@ use urlencoding::encode; use crate::compile; use crate::gui::new_window; -use crate::pdl::interpreter::run_file_sync as runr; -use crate::pdl::run::run_pdl_program; +use crate::pdl::interpreter::run_file_sync as run; #[cfg(desktop)] pub fn setup(app: &mut tauri::App) -> Result> { @@ -50,11 +49,16 @@ pub fn setup(app: &mut tauri::App) -> Result> _ => Err(Box::from("Unsupported compile command")), } } - "runr" => runr( + "run" => run( subcommand_args .get("source") .and_then(|a| a.value.as_str()) .expect("valid positional source arg"), + subcommand_args.get("trace").and_then(|a| a.value.as_str()), + subcommand_args.get("data").and_then(|a| a.value.as_str()), + subcommand_args + .get("data-file") + .and_then(|a| a.value.as_str()), subcommand_args .get("debug") .and_then(|a| a.value.as_bool()) @@ -67,16 +71,6 @@ pub fn setup(app: &mut tauri::App) -> Result> == Some(false), ) .and_then(|_trace| Ok(true)), - "run" => run_pdl_program( - subcommand_args - .get("source") - .and_then(|a| a.value.as_str()) - .expect("valid positional source arg"), - subcommand_args.get("trace").and_then(|a| a.value.as_str()), - subcommand_args.get("data").and_then(|a| a.value.as_str()), - subcommand_args.get("stream").and_then(|a| a.value.as_str()), - ) - .and_then(|()| Ok(true)), "view" => new_window( app.handle().clone(), subcommand_args.get("trace").and_then(|a| { diff --git a/pdl-live-react/src-tauri/src/pdl/interpreter.rs b/pdl-live-react/src-tauri/src/pdl/interpreter.rs index b92c164cb..7ace47581 100644 --- a/pdl-live-react/src-tauri/src/pdl/interpreter.rs +++ b/pdl-live-react/src-tauri/src/pdl/interpreter.rs @@ -1054,7 +1054,14 @@ pub async fn run_file(source_file_path: &str, debug: bool, stream: bool) -> Inte run(&program, cwd, debug, stream).await } -pub fn run_file_sync(source_file_path: &str, debug: bool, stream: bool) -> InterpretationSync { +pub fn run_file_sync( + source_file_path: &str, + _trace: Option<&str>, + _data: Option<&str>, + _data_file: Option<&str>, + debug: bool, + stream: bool, +) -> InterpretationSync { tauri::async_runtime::block_on(run_file(source_file_path, debug, stream)) .map_err(|err| Box::::from(err.to_string())) } diff --git a/pdl-live-react/src-tauri/src/pdl/mod.rs b/pdl-live-react/src-tauri/src/pdl/mod.rs index fcdcab28b..179cb9e10 100644 --- a/pdl-live-react/src-tauri/src/pdl/mod.rs +++ b/pdl-live-react/src-tauri/src/pdl/mod.rs @@ -5,4 +5,3 @@ mod interpreter_tests; pub mod pip; pub mod pull; pub mod requirements; -pub mod run; diff --git a/pdl-live-react/src-tauri/src/pdl/pull.rs b/pdl-live-react/src-tauri/src/pdl/pull.rs index cb7763c61..7b11e3113 100644 --- a/pdl-live-react/src-tauri/src/pdl/pull.rs +++ b/pdl-live-react/src-tauri/src/pdl/pull.rs @@ -6,16 +6,15 @@ use rayon::prelude::*; use crate::pdl::ast::PdlBlock; use crate::pdl::extract; -use crate::pdl::interpreter::parse_file; -pub async fn pull_if_needed_from_path( +/* pub async fn pull_if_needed_from_path( source_file_path: &str, ) -> Result<(), Box> { let program = parse_file(&::std::path::PathBuf::from(source_file_path))?; pull_if_needed(&program) .await .map_err(|e| Box::from(e.to_string())) -} +} */ /// Pull models (in parallel) from the PDL program in the given filepath. pub async fn pull_if_needed(program: &PdlBlock) -> Result<(), Error> { diff --git a/pdl-live-react/src-tauri/src/pdl/requirements.rs b/pdl-live-react/src-tauri/src/pdl/requirements.rs index 2b08c9f16..6e6bb0501 100644 --- a/pdl-live-react/src-tauri/src/pdl/requirements.rs +++ b/pdl-live-react/src-tauri/src/pdl/requirements.rs @@ -1,5 +1,2 @@ -//pub const PDL_INTERPRETER: &str = "-e ../"; -pub const PDL_INTERPRETER: &str = "prompt-declaration-language==0.6.0"; - pub const BEEAI_FRAMEWORK: &str = "-e git+https://github.com/starpit/bee-agent-framework.git@nick-meta-combo#egg=beeai_framework&subdirectory=python"; //pub const BEEAI_FRAMEWORK: &str = "beeai_framework==0.1"; diff --git a/pdl-live-react/src-tauri/src/pdl/run.rs b/pdl-live-react/src-tauri/src/pdl/run.rs deleted file mode 100644 index ee7281f93..000000000 --- a/pdl-live-react/src-tauri/src/pdl/run.rs +++ /dev/null @@ -1,52 +0,0 @@ -use ::std::path::Path; -use duct::cmd; -use futures::executor::block_on; - -use crate::pdl::pip::pip_install_if_needed; -use crate::pdl::pull::pull_if_needed_from_path; -use crate::pdl::requirements::PDL_INTERPRETER; - -#[cfg(desktop)] -pub fn run_pdl_program( - source_file_path: &str, - trace_file: Option<&str>, - data: Option<&str>, - stream: Option<&str>, -) -> Result<(), Box> { - println!( - "Running {:#?}", - Path::new(&source_file_path).file_name().unwrap() - ); - - // async the model pull and pip installs - let pull_future = pull_if_needed_from_path(&source_file_path); - let bin_path_future = pip_install_if_needed(&PDL_INTERPRETER); - - // wait for any model pulls to finish - if let Err(e) = block_on(pull_future) { - return Err(e); - } - - // wait for any pip installs to finish - let bin_path = block_on(bin_path_future)?; - - let mut args = vec![ - source_file_path.to_string(), - dashdash("--trace", trace_file), - dashdash("--data", data), - dashdash("--stream", stream), - ]; - args.retain(|x| x.chars().count() > 0); - cmd(bin_path.join("pdl"), &args).run()?; - - Ok(()) -} - -/// Format `--{opt}={a}` based on whether `a` is given or not -fn dashdash(opt: &str, a: Option<&str>) -> String { - if let Some(s) = a { - format!("{}={}", opt, s) - } else { - "".to_owned() - } -} diff --git a/pdl-live-react/src-tauri/tauri.conf.json b/pdl-live-react/src-tauri/tauri.conf.json index 108356584..f37c55cd1 100644 --- a/pdl-live-react/src-tauri/tauri.conf.json +++ b/pdl-live-react/src-tauri/tauri.conf.json @@ -47,7 +47,8 @@ } } }, - "runr": { + "run": { + "description": "Run a PDL program", "args": [ { "name": "source", @@ -59,31 +60,20 @@ "name": "no-stream" }, { - "name": "debug", - "short": "g" - } - ] - }, - "run": { - "description": "Run a PDL program", - "args": [ - { - "name": "source", - "index": 1, - "required": true, + "name": "data", "takesValue": true }, { - "name": "stream", + "name": "data-file", "takesValue": true }, { - "name": "data", + "name": "trace", "takesValue": true }, { - "name": "trace", - "takesValue": true + "name": "debug", + "short": "g" } ] },