Skip to content

Commit 5d443d7

Browse files
authored
Merge pull request #100 from Origen-SDK/launcher
Command Launcher Update
2 parents bbf4dc6 + 29462e0 commit 5d443d7

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

rust/origen/cli/src/commands/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub fn launch(
2020
);
2121

2222
if let Some(t) = targets {
23-
let _t: Vec<String> = t.iter().map(|__t| format!("'{}'", __t)).collect();
23+
// added r prefix to the string to force python to interpret as a string literal
24+
let _t: Vec<String> = t.iter().map(|__t| format!("r'{}'", __t)).collect();
2425
cmd += &format!(", targets=[{}]", &_t.join(",")).to_string();
2526
}
2627

@@ -30,7 +31,8 @@ pub fn launch(
3031
}
3132

3233
if files.is_some() {
33-
let f: Vec<String> = files.unwrap().iter().map(|f| format!("'{}'", f)).collect();
34+
// added r prefix to the string to force python to interpret as a string literal
35+
let f: Vec<String> = files.unwrap().iter().map(|f| format!("r'{}'", f)).collect();
3436
cmd += &format!(", files=[{}]", f.join(",")).to_string();
3537
}
3638

rust/origen/cli/src/commands/setup.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ extern crate time;
22

33
use crate::python::{poetry_version, MIN_PYTHON_VERSION, PYTHON_CONFIG};
44
use online::online;
5-
use origen::core::os;
65
use origen::core::term::*;
76
use std::fs;
87
use std::io;
98
use std::path::PathBuf;
9+
use std::process::Command;
1010

1111
const POETRY_INSTALLER: &str =
1212
"https://raw.githubusercontent.com/sdispater/poetry/1.0.0b7/get-poetry.py";
@@ -69,16 +69,16 @@ pub fn run() {
6969
fs::write(&get_poetry_file, new_data).expect("Unable to write Poetry install file");
7070

7171
// Install Poetry
72-
os::cmd(&PYTHON_CONFIG.command)
73-
.arg(format!("{}", get_poetry_file.display()))
72+
Command::new(&PYTHON_CONFIG.command)
73+
.arg(get_poetry_file)
7474
.arg("--yes")
7575
.status()
7676
.expect("Something went wrong install Poetry");
7777

7878
if poetry_version().unwrap().major != 1 {
7979
// Have to use --preview here to get a 1.0.0 pre version, can only use versions for
8080
// official releases
81-
os::cmd(&PYTHON_CONFIG.poetry_command)
81+
Command::new(&PYTHON_CONFIG.poetry_command)
8282
.arg("self:update")
8383
.arg("--preview")
8484
.status()
@@ -90,7 +90,7 @@ pub fn run() {
9090

9191
print!("Are the app's deps. installed? ... ");
9292

93-
let status = os::cmd(&PYTHON_CONFIG.poetry_command)
93+
let status = Command::new(&PYTHON_CONFIG.poetry_command)
9494
.arg("install")
9595
.arg("--no-root")
9696
.status();

rust/origen/cli/src/python.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Responsible for managing Python execution
22

3-
use origen::core::os;
3+
use std::process::Command;
44
use origen::STATUS;
55
use semver::Version;
6+
use std::path::PathBuf;
67

78
const PYTHONS: &[&str] = &[
89
"python",
@@ -23,7 +24,7 @@ pub struct Config {
2324
pub command: String,
2425
pub version: Version,
2526
pub error: String,
26-
pub poetry_command: String,
27+
pub poetry_command: PathBuf,
2728
}
2829

2930
impl Default for Config {
@@ -33,10 +34,9 @@ impl Default for Config {
3334
match get_version(cmd) {
3435
Some(version) => {
3536
available = true;
36-
let poetry_cmd = format!(
37-
"{}/.poetry/bin/poetry",
38-
format!("{}", STATUS.home.display())
39-
);
37+
let mut poetry_cmd = PathBuf::from(&STATUS.home);
38+
for d in [".poetry", "bin", "poetry"].iter() { poetry_cmd.push(d) }
39+
if cfg!(windows) { poetry_cmd.set_extension("bat"); }
4040
if version >= Version::parse(MIN_PYTHON_VERSION).unwrap() {
4141
return Config {
4242
available: true,
@@ -56,25 +56,25 @@ impl Default for Config {
5656
}
5757
Config {
5858
available: false,
59-
command: "".to_string(),
59+
command: String::new(),
6060
version: Version::parse("0.0.0").unwrap(),
6161
error: msg,
62-
poetry_command: "".to_string(),
62+
poetry_command: PathBuf::new(),
6363
}
6464
}
6565
}
6666

6767
/// Get the Python version from the given command
6868
fn get_version(command: &str) -> Option<Version> {
69-
match os::cmd(command).arg("--version").output() {
69+
match Command::new(command).arg("--version").output() {
7070
Ok(output) => return extract_version(std::str::from_utf8(&output.stdout).unwrap()),
7171
Err(_e) => return None,
7272
}
7373
}
7474

7575
/// Returns the version of poetry (obtained from running "poetry --version")
7676
pub fn poetry_version() -> Option<Version> {
77-
match os::cmd(&PYTHON_CONFIG.poetry_command)
77+
match Command::new(&PYTHON_CONFIG.poetry_command)
7878
.arg("--version")
7979
.output()
8080
{
@@ -100,7 +100,7 @@ fn extract_version(text: &str) -> Option<Version> {
100100

101101
/// Execute the given Python code
102102
pub fn run(code: &str) {
103-
let _status = os::cmd(&PYTHON_CONFIG.poetry_command)
103+
let _status = Command::new(&PYTHON_CONFIG.poetry_command)
104104
.arg("run")
105105
.arg(&PYTHON_CONFIG.command)
106106
.arg("-c")

rust/origen/src/core/os.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::process::Command;
2-
31
pub fn on_windows() -> bool {
42
if cfg!(windows) {
53
return true;
@@ -15,17 +13,3 @@ pub fn on_linux() -> bool {
1513
return false;
1614
};
1715
}
18-
19-
// Due to OS differences, the basic std::process::Command doesn't cooperate very well in a Windows environment.
20-
// Instead, wrap the cmd function here, which will ensures some semblance between Windows and Linux commands.
21-
#[allow(unused_mut)]
22-
pub fn cmd(cmd: &str) -> std::process::Command {
23-
if on_windows() {
24-
let mut c = Command::new("cmd");
25-
c.arg("/C").arg(&cmd);
26-
return c;
27-
} else {
28-
let mut c = Command::new(&cmd);
29-
return c;
30-
}
31-
}

0 commit comments

Comments
 (0)