i added so much that its hard to remember what i added.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
use crate::rs_println;
|
||||
|
||||
use std::fs;
|
||||
use std::ffi::CString;
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyList;
|
||||
use std::env;
|
||||
|
||||
|
||||
pub fn start() -> PyResult<()> {
|
||||
rs_println!("Running Python program...");
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "\\src\\python");
|
||||
|
||||
let code = get_code(&(path.to_owned() + "\\main.py"));
|
||||
let app_path = CString::new(code).unwrap();
|
||||
|
||||
pyo3::prepare_freethreaded_python();
|
||||
let from_python = Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
||||
let syspath = py
|
||||
.import("sys")?
|
||||
.getattr("path")?
|
||||
.downcast_into::<PyList>()?;
|
||||
|
||||
syspath.insert(0, path)?;
|
||||
let empty = CString::new("").unwrap();
|
||||
|
||||
let app: Py<PyAny> = PyModule::from_code(py, &app_path, &empty, &empty)?
|
||||
.getattr("run")?
|
||||
.into();
|
||||
|
||||
return app.call0(py);
|
||||
});
|
||||
|
||||
println!("py: {}", from_python?);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn get_code(path: &str) -> String {
|
||||
return fs::read_to_string(path)
|
||||
.expect("Failed to read Python file.")
|
||||
.to_string();
|
||||
}
|
||||
Reference in New Issue
Block a user