feat(python): add interface file and other small changes

This commit is contained in:
Anand Balakrishnan 2023-04-30 22:14:33 -07:00
parent 168e881884
commit c42f892099
No known key found for this signature in database
8 changed files with 373 additions and 31 deletions

View file

@ -2,8 +2,31 @@ mod expr;
mod semantics;
mod signals;
use argus_core::ArgusError;
use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyTypeError, PyValueError};
use pyo3::prelude::*;
#[derive(derive_more::From)]
struct PyArgusError(ArgusError);
impl From<PyArgusError> for PyErr {
fn from(value: PyArgusError) -> Self {
use argus_core::Error::*;
match value.0 {
err @ (IncompleteArgs | InvalidOperation | IdentifierRedeclaration) => {
PyValueError::new_err(err.to_string())
}
err @ (InvalidPushToSignal
| NonMonotonicSignal {
end_time: _,
current_sample: _,
}) => PyRuntimeError::new_err(err.to_string()),
err @ SignalNotPresent => PyKeyError::new_err(err.to_string()),
err @ (InvalidSignalType | InvalidCast { from: _, to: _ }) => PyTypeError::new_err(err.to_string()),
}
}
}
#[pymodule]
#[pyo3(name = "_argus")]
fn pyargus(py: Python, m: &PyModule) -> PyResult<()> {