mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 16:02:18 +00:00
* chore: improve release pipeline * fix pipelines * fix sccache * update workflows * fix workflow * update workflow * remove sccache and cross * bring back sccache * fix pipelines * fix nodejs build * fix pipelines * move python to abi3 for future proofing * fix workflow ordering bug * gate releases via environment - configure go via release * set release as 1.0.0-beta
48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use anyhow::Context;
|
|
use pyo3::prelude::{PyAnyMethods, PyStringMethods};
|
|
use pyo3::types::PyString;
|
|
use pyo3::{pyclass, pymethods, Bound, FromPyObject, PyAny, PyResult};
|
|
use pythonize::depythonize;
|
|
use std::sync::Arc;
|
|
use zen_engine::model::DecisionContent;
|
|
|
|
#[pyclass]
|
|
#[pyo3(name = "ZenDecisionContent")]
|
|
pub struct PyZenDecisionContent(pub Arc<DecisionContent>);
|
|
|
|
#[pymethods]
|
|
impl PyZenDecisionContent {
|
|
#[new]
|
|
pub fn new(data: &str) -> PyResult<Self> {
|
|
let mut content: DecisionContent =
|
|
serde_json::from_str(data).context("Failed to parse JSON")?;
|
|
if let DecisionContent::Graph(g) = &mut content {
|
|
g.compile();
|
|
}
|
|
Ok(Self(Arc::new(content)))
|
|
}
|
|
}
|
|
|
|
pub struct PyZenDecisionContentJson(pub PyZenDecisionContent);
|
|
|
|
impl<'py> FromPyObject<'py> for PyZenDecisionContentJson {
|
|
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
|
|
if let Ok(s) = ob.downcast::<PyZenDecisionContent>() {
|
|
let borrow_ref = s.borrow();
|
|
let content = borrow_ref.0.clone();
|
|
|
|
return Ok(Self(PyZenDecisionContent(content)));
|
|
}
|
|
|
|
if let Ok(b) = ob.downcast::<PyString>() {
|
|
let str = b.to_cow()?;
|
|
let content = serde_json::from_str(&str).context("Invalid JSON")?;
|
|
|
|
return Ok(Self(PyZenDecisionContent(Arc::new(content))));
|
|
}
|
|
|
|
let content = depythonize(ob)?;
|
|
Ok(Self(PyZenDecisionContent(Arc::new(content))))
|
|
}
|
|
}
|