Skip to content

Commit

Permalink
fix run py
Browse files Browse the repository at this point in the history
  • Loading branch information
super1207 committed Aug 13, 2024
1 parent 1131427 commit cb018c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion res/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.75
0.0.76
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,21 @@ pub struct Asset;
pub struct AssetDoc;


pub fn get_python_cmd_name() -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
#[cfg(not(windows))]
return Ok("python3".to_owned());

#[cfg(windows)]
return Ok("python".to_owned());
}

pub fn get_local_python_uid() -> Result<String,Box<dyn std::error::Error>> {


#[cfg(windows)]
use std::os::windows::process::CommandExt;

let mut command = std::process::Command::new("python3");
let mut command = std::process::Command::new(get_python_cmd_name().unwrap());

#[cfg(windows)]
let output = command.creation_flags(0x08000000).arg("-c").arg("import sys; print(sys.version)").output()?;
Expand Down Expand Up @@ -575,10 +583,10 @@ fn create_python_env() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
#[cfg(windows)]
use std::os::windows::process::CommandExt;
#[cfg(windows)]
let foo = std::process::Command::new("python3").creation_flags(0x08000000).current_dir(app_dir).arg("-m").arg("venv").arg("pymain").status();
let foo = std::process::Command::new(get_python_cmd_name()?).creation_flags(0x08000000).current_dir(app_dir).arg("-m").arg("venv").arg("pymain").status();

#[cfg(not(windows))]
let foo = std::process::Command::new("python3").current_dir(app_dir).arg("-m").arg("venv").arg("pymain").status();
let foo = std::process::Command::new(get_python_cmd_name()?).current_dir(app_dir).arg("-m").arg("venv").arg("pymain").status();

if foo.is_err() {
return Err(format!("python环境创建失败:{:?}",foo).into());
Expand Down Expand Up @@ -758,7 +766,7 @@ conn_fun()


#[cfg(windows)]
let foo = std::process::Command::new("python3").creation_flags(0x08000000)
let foo = std::process::Command::new(get_python_cmd_name().unwrap()).creation_flags(0x08000000)
.env("PATH", new_env)
.arg("-c")
.arg(code)
Expand All @@ -768,7 +776,7 @@ conn_fun()


#[cfg(not(windows))]
let foo = std::process::Command::new("python3")
let foo = std::process::Command::new(get_python_cmd_name().unwrap())
.env("PATH", new_env)
.arg("-c")
.arg(code)
Expand Down
14 changes: 7 additions & 7 deletions src/redlang/exfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::RedLang;
use reqwest::header::HeaderName;
use reqwest::header::HeaderValue;
use std::io::Write;
use crate::{add_file_lock, cq_add_log_w, cqapi::{cq_add_log, get_tmp_dir}, cronevent::{OneTimeRunStruct, G_ONE_TIME_RUN}, del_file_lock, pyserver::call_py_block, redlang::get_random, G_DEFAULF_FONT, G_QUIT_FLAG, RT_PTR};
use crate::{add_file_lock, cq_add_log_w, cqapi::{cq_add_log, get_tmp_dir}, cronevent::{OneTimeRunStruct, G_ONE_TIME_RUN}, del_file_lock, get_python_cmd_name, pyserver::call_py_block, redlang::get_random, G_DEFAULF_FONT, G_QUIT_FLAG, RT_PTR};

use image::{AnimationDecoder, EncodableLayout, GenericImageView, ImageBuffer, ImageFormat, Rgba};
use imageproc::geometric_transformations::{Projection, warp_with, rotate_about_center};
Expand Down Expand Up @@ -3019,10 +3019,10 @@ def red_out(sw):


#[cfg(windows)]
let foo = std::process::Command::new("python3").creation_flags(0x08000000).current_dir(python_dir.clone()).arg("-m").arg("venv").arg("pymain").status();
let foo = std::process::Command::new(get_python_cmd_name().unwrap()).creation_flags(0x08000000).current_dir(python_dir.clone()).arg("-m").arg("venv").arg("pymain").status();

#[cfg(not(windows))]
let foo = std::process::Command::new("python3").current_dir(python_dir.clone()).arg("-m").arg("venv").arg("pymain").status();
let foo = std::process::Command::new(get_python_cmd_name().unwrap()).current_dir(python_dir.clone()).arg("-m").arg("venv").arg("pymain").status();

if foo.is_err() {
return Err(RedLang::make_err(&format!("python环境创建失败:{:?}",foo.err())));
Expand Down Expand Up @@ -3050,7 +3050,7 @@ def red_out(sw):
let red_py_decode = crate::G_RED_PY_DECODE.to_owned();

#[cfg(windows)]
let mut p = std::process::Command::new("python3").creation_flags(0x08000000)
let mut p = std::process::Command::new(get_python_cmd_name().unwrap()).creation_flags(0x08000000)
.stdin(pip_in)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
Expand All @@ -3062,7 +3062,7 @@ def red_out(sw):


#[cfg(not(windows))]
let mut p = std::process::Command::new("python3")
let mut p = std::process::Command::new(get_python_cmd_name().unwrap())
.stdin(pip_in)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
Expand Down Expand Up @@ -3131,7 +3131,7 @@ def red_out(sw):
use std::os::windows::process::CommandExt;

#[cfg(not(windows))]
let mut p = std::process::Command::new("python3")
let mut p = std::process::Command::new(get_python_cmd_name().unwrap())
.stdin(pip_in)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
Expand All @@ -3142,7 +3142,7 @@ def red_out(sw):


#[cfg(windows)]
let mut p = std::process::Command::new("python3").creation_flags(0x08000000)
let mut p = std::process::Command::new(get_python_cmd_name().unwrap()).creation_flags(0x08000000)
.stdin(pip_in)
.stdout(std::process::Stdio::piped())
.stderr(std::process::Stdio::piped())
Expand Down

0 comments on commit cb018c4

Please sign in to comment.