use crate::{Result, cache::Cache, helper::load_script};
use pyo3::prelude::*;
use std::ffi::CString;
pub fn exec(module: &str) -> Result<Vec<String>> {
Python::initialize();
let script = load_script(module)?;
let cache = Cache::new()?;
let sps = serde_json::to_string(&cache.get_problems()?)?;
let stags = serde_json::to_string(&cache.get_tags()?)?;
Python::attach(|py| {
let script_cstr = CString::new(script.as_str())?;
let filename_cstr = CString::new("plan.py")?;
let module_name_cstr = CString::new("plan")?;
let pym = PyModule::from_code(py, &script_cstr, &filename_cstr, &module_name_cstr)?;
pym.getattr("plan")?.call1((sps, stags))?.extract()
})
.map_err(Into::into)
}