i added so much that its hard to remember what i added.

This commit is contained in:
2025-02-05 19:23:49 +01:00
parent 04a0efcfd7
commit 3f2c628830
9 changed files with 226 additions and 132 deletions
+43
View File
@@ -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();
}