diff --git a/rust/origen/cli/src/commands/mod.rs b/rust/origen/cli/src/commands/mod.rs index cd05c063..47df683b 100644 --- a/rust/origen/cli/src/commands/mod.rs +++ b/rust/origen/cli/src/commands/mod.rs @@ -20,7 +20,8 @@ pub fn launch( ); if let Some(t) = targets { - let _t: Vec = t.iter().map(|__t| format!("'{}'", __t)).collect(); + // added r prefix to the string to force python to interpret as a string literal + let _t: Vec = t.iter().map(|__t| format!("r'{}'", __t)).collect(); cmd += &format!(", targets=[{}]", &_t.join(",")).to_string(); } @@ -30,7 +31,8 @@ pub fn launch( } if files.is_some() { - let f: Vec = files.unwrap().iter().map(|f| format!("'{}'", f)).collect(); + // added r prefix to the string to force python to interpret as a string literal + let f: Vec = files.unwrap().iter().map(|f| format!("r'{}'", f)).collect(); cmd += &format!(", files=[{}]", f.join(",")).to_string(); } diff --git a/rust/origen/cli/src/commands/setup.rs b/rust/origen/cli/src/commands/setup.rs index ce66dd4a..2ffe6f39 100644 --- a/rust/origen/cli/src/commands/setup.rs +++ b/rust/origen/cli/src/commands/setup.rs @@ -2,11 +2,11 @@ extern crate time; use crate::python::{poetry_version, MIN_PYTHON_VERSION, PYTHON_CONFIG}; use online::online; -use origen::core::os; use origen::core::term::*; use std::fs; use std::io; use std::path::PathBuf; +use std::process::Command; const POETRY_INSTALLER: &str = "https://raw.githubusercontent.com/sdispater/poetry/1.0.0b7/get-poetry.py"; @@ -69,8 +69,8 @@ pub fn run() { fs::write(&get_poetry_file, new_data).expect("Unable to write Poetry install file"); // Install Poetry - os::cmd(&PYTHON_CONFIG.command) - .arg(format!("{}", get_poetry_file.display())) + Command::new(&PYTHON_CONFIG.command) + .arg(get_poetry_file) .arg("--yes") .status() .expect("Something went wrong install Poetry"); @@ -78,7 +78,7 @@ pub fn run() { if poetry_version().unwrap().major != 1 { // Have to use --preview here to get a 1.0.0 pre version, can only use versions for // official releases - os::cmd(&PYTHON_CONFIG.poetry_command) + Command::new(&PYTHON_CONFIG.poetry_command) .arg("self:update") .arg("--preview") .status() @@ -90,7 +90,7 @@ pub fn run() { print!("Are the app's deps. installed? ... "); - let status = os::cmd(&PYTHON_CONFIG.poetry_command) + let status = Command::new(&PYTHON_CONFIG.poetry_command) .arg("install") .arg("--no-root") .status(); diff --git a/rust/origen/cli/src/python.rs b/rust/origen/cli/src/python.rs index df80f87c..bfb1b552 100644 --- a/rust/origen/cli/src/python.rs +++ b/rust/origen/cli/src/python.rs @@ -1,8 +1,9 @@ // Responsible for managing Python execution -use origen::core::os; +use std::process::Command; use origen::STATUS; use semver::Version; +use std::path::PathBuf; const PYTHONS: &[&str] = &[ "python", @@ -23,7 +24,7 @@ pub struct Config { pub command: String, pub version: Version, pub error: String, - pub poetry_command: String, + pub poetry_command: PathBuf, } impl Default for Config { @@ -33,10 +34,9 @@ impl Default for Config { match get_version(cmd) { Some(version) => { available = true; - let poetry_cmd = format!( - "{}/.poetry/bin/poetry", - format!("{}", STATUS.home.display()) - ); + let mut poetry_cmd = PathBuf::from(&STATUS.home); + for d in [".poetry", "bin", "poetry"].iter() { poetry_cmd.push(d) } + if cfg!(windows) { poetry_cmd.set_extension("bat"); } if version >= Version::parse(MIN_PYTHON_VERSION).unwrap() { return Config { available: true, @@ -56,17 +56,17 @@ impl Default for Config { } Config { available: false, - command: "".to_string(), + command: String::new(), version: Version::parse("0.0.0").unwrap(), error: msg, - poetry_command: "".to_string(), + poetry_command: PathBuf::new(), } } } /// Get the Python version from the given command fn get_version(command: &str) -> Option { - match os::cmd(command).arg("--version").output() { + match Command::new(command).arg("--version").output() { Ok(output) => return extract_version(std::str::from_utf8(&output.stdout).unwrap()), Err(_e) => return None, } @@ -74,7 +74,7 @@ fn get_version(command: &str) -> Option { /// Returns the version of poetry (obtained from running "poetry --version") pub fn poetry_version() -> Option { - match os::cmd(&PYTHON_CONFIG.poetry_command) + match Command::new(&PYTHON_CONFIG.poetry_command) .arg("--version") .output() { @@ -100,7 +100,7 @@ fn extract_version(text: &str) -> Option { /// Execute the given Python code pub fn run(code: &str) { - let _status = os::cmd(&PYTHON_CONFIG.poetry_command) + let _status = Command::new(&PYTHON_CONFIG.poetry_command) .arg("run") .arg(&PYTHON_CONFIG.command) .arg("-c") diff --git a/rust/origen/src/core/os.rs b/rust/origen/src/core/os.rs index 45c553e5..a167c026 100644 --- a/rust/origen/src/core/os.rs +++ b/rust/origen/src/core/os.rs @@ -1,5 +1,3 @@ -use std::process::Command; - pub fn on_windows() -> bool { if cfg!(windows) { return true; @@ -15,17 +13,3 @@ pub fn on_linux() -> bool { return false; }; } - -// Due to OS differences, the basic std::process::Command doesn't cooperate very well in a Windows environment. -// Instead, wrap the cmd function here, which will ensures some semblance between Windows and Linux commands. -#[allow(unused_mut)] -pub fn cmd(cmd: &str) -> std::process::Command { - if on_windows() { - let mut c = Command::new("cmd"); - c.arg("/C").arg(&cmd); - return c; - } else { - let mut c = Command::new(&cmd); - return c; - } -}