refactor(pyargus): make pyargus depend only on argus

This commit is contained in:
Anand Balakrishnan 2023-10-03 17:34:17 -07:00
parent db3a63f9e1
commit 444d60197d
No known key found for this signature in database
6 changed files with 32 additions and 64 deletions

View file

@ -12,8 +12,7 @@ name = "pyargus"
crate-type = ["cdylib"]
[dependencies]
argus-core = { version = "0.1.0", path = "../argus-core" }
argus-semantics = { version = "0.1.0", path = "../argus-semantics" }
argus = { version = "0.1.0", path = "../argus" }
derive_more = "0.99.17"
log = "0.4.20"
paste = "1.0.14"

View file

@ -1,6 +1,6 @@
use std::time::Duration;
use argus_core::prelude::*;
use argus::expr::*;
use pyo3::prelude::*;
use pyo3::pyclass::CompareOp;
@ -62,7 +62,7 @@ pub struct ConstInt;
impl ConstInt {
#[new]
fn new(val: i64) -> (Self, PyNumExpr) {
(Self, Box::new(NumExpr::IntLit(argus_core::expr::IntLit(val))).into())
(Self, Box::new(NumExpr::IntLit(argus::expr::IntLit(val))).into())
}
}
@ -79,7 +79,7 @@ pub struct ConstUInt;
impl ConstUInt {
#[new]
fn new(val: u64) -> (Self, PyNumExpr) {
(Self, Box::new(NumExpr::UIntLit(argus_core::expr::UIntLit(val))).into())
(Self, Box::new(NumExpr::UIntLit(argus::expr::UIntLit(val))).into())
}
}
@ -91,10 +91,7 @@ pub struct ConstFloat;
impl ConstFloat {
#[new]
fn new(val: f64) -> (Self, PyNumExpr) {
(
Self,
Box::new(NumExpr::FloatLit(argus_core::expr::FloatLit(val))).into(),
)
(Self, Box::new(NumExpr::FloatLit(argus::expr::FloatLit(val))).into())
}
}
@ -106,10 +103,7 @@ pub struct VarInt;
impl VarInt {
#[new]
fn new(name: String) -> (Self, PyNumExpr) {
(
Self,
Box::new(NumExpr::IntVar(argus_core::expr::IntVar { name })).into(),
)
(Self, Box::new(NumExpr::IntVar(argus::expr::IntVar { name })).into())
}
}
@ -121,10 +115,7 @@ pub struct VarUInt;
impl VarUInt {
#[new]
fn new(name: String) -> (Self, PyNumExpr) {
(
Self,
Box::new(NumExpr::UIntVar(argus_core::expr::UIntVar { name })).into(),
)
(Self, Box::new(NumExpr::UIntVar(argus::expr::UIntVar { name })).into())
}
}
@ -136,10 +127,7 @@ pub struct VarFloat;
impl VarFloat {
#[new]
fn new(name: String) -> (Self, PyNumExpr) {
(
Self,
Box::new(NumExpr::FloatVar(argus_core::expr::FloatVar { name })).into(),
)
(Self, Box::new(NumExpr::FloatVar(argus::expr::FloatVar { name })).into())
}
}
@ -152,7 +140,7 @@ impl Negate {
#[new]
fn new(arg: PyNumExpr) -> (Self, PyNumExpr) {
let arg = arg.0;
(Self, Box::new(NumExpr::Neg(argus_core::expr::Neg { arg })).into())
(Self, Box::new(NumExpr::Neg(argus::expr::Neg { arg })).into())
}
}
@ -167,7 +155,7 @@ impl Add {
#[new]
fn new(args: Vec<PyNumExpr>) -> (Self, PyNumExpr) {
let args: Vec<NumExpr> = args.into_iter().map(|arg| *arg.0).collect();
(Self, Box::new(NumExpr::Add(argus_core::expr::Add { args })).into())
(Self, Box::new(NumExpr::Add(argus::expr::Add { args })).into())
}
}
@ -180,7 +168,7 @@ impl Sub {
fn new(lhs: PyNumExpr, rhs: PyNumExpr) -> (Self, PyNumExpr) {
let lhs = lhs.0;
let rhs = rhs.0;
(Self, Box::new(NumExpr::Sub(argus_core::expr::Sub { lhs, rhs })).into())
(Self, Box::new(NumExpr::Sub(argus::expr::Sub { lhs, rhs })).into())
}
}
@ -192,7 +180,7 @@ impl Mul {
#[new]
fn new(args: Vec<PyNumExpr>) -> (Self, PyNumExpr) {
let args: Vec<NumExpr> = args.into_iter().map(|arg| *arg.0).collect();
(Self, Box::new(NumExpr::Mul(argus_core::expr::Mul { args })).into())
(Self, Box::new(NumExpr::Mul(argus::expr::Mul { args })).into())
}
}
@ -207,7 +195,7 @@ impl Div {
let divisor = divisor.0;
(
Self,
Box::new(NumExpr::Div(argus_core::expr::Div { dividend, divisor })).into(),
Box::new(NumExpr::Div(argus::expr::Div { dividend, divisor })).into(),
)
}
}
@ -220,7 +208,7 @@ impl Abs {
#[new]
fn new(arg: PyNumExpr) -> (Self, PyNumExpr) {
let arg = arg.0;
(Self, Box::new(NumExpr::Abs(argus_core::expr::Abs { arg })).into())
(Self, Box::new(NumExpr::Abs(argus::expr::Abs { arg })).into())
}
}
@ -254,7 +242,7 @@ pub struct ConstBool;
impl ConstBool {
#[new]
fn new(val: bool) -> (Self, PyBoolExpr) {
(Self, Box::new(BoolExpr::BoolLit(argus_core::expr::BoolLit(val))).into())
(Self, Box::new(BoolExpr::BoolLit(argus::expr::BoolLit(val))).into())
}
}
@ -265,10 +253,7 @@ pub struct VarBool;
impl VarBool {
#[new]
fn new(name: String) -> (Self, PyBoolExpr) {
(
Self,
Box::new(BoolExpr::BoolVar(argus_core::expr::BoolVar { name })).into(),
)
(Self, Box::new(BoolExpr::BoolVar(argus::expr::BoolVar { name })).into())
}
}
@ -284,10 +269,7 @@ impl Cmp {
let op = op.0;
let lhs = lhs.0;
let rhs = rhs.0;
(
Self,
Box::new(BoolExpr::Cmp(argus_core::expr::Cmp { op, lhs, rhs })).into(),
)
(Self, Box::new(BoolExpr::Cmp(argus::expr::Cmp { op, lhs, rhs })).into())
}
}
@ -332,7 +314,7 @@ impl Not {
#[new]
fn new(arg: PyBoolExpr) -> (Self, PyBoolExpr) {
let arg = arg.0;
(Self, PyBoolExpr(Box::new(BoolExpr::Not(argus_core::expr::Not { arg }))))
(Self, PyBoolExpr(Box::new(BoolExpr::Not(argus::expr::Not { arg }))))
}
}
@ -344,10 +326,7 @@ impl And {
#[new]
fn new(args: Vec<PyBoolExpr>) -> (Self, PyBoolExpr) {
let args: Vec<BoolExpr> = args.into_iter().map(|arg| *arg.0).collect();
(
Self,
PyBoolExpr(Box::new(BoolExpr::And(argus_core::expr::And { args }))),
)
(Self, PyBoolExpr(Box::new(BoolExpr::And(argus::expr::And { args }))))
}
}
@ -359,7 +338,7 @@ impl Or {
#[new]
fn new(args: Vec<PyBoolExpr>) -> (Self, PyBoolExpr) {
let args: Vec<BoolExpr> = args.into_iter().map(|arg| *arg.0).collect();
(Self, PyBoolExpr(Box::new(BoolExpr::Or(argus_core::expr::Or { args }))))
(Self, PyBoolExpr(Box::new(BoolExpr::Or(argus::expr::Or { args }))))
}
}
@ -371,10 +350,7 @@ impl Next {
#[new]
fn new(arg: PyBoolExpr) -> (Self, PyBoolExpr) {
let arg = arg.0;
(
Self,
PyBoolExpr(Box::new(BoolExpr::Next(argus_core::expr::Next { arg }))),
)
(Self, PyBoolExpr(Box::new(BoolExpr::Next(argus::expr::Next { arg }))))
}
}
@ -395,7 +371,7 @@ impl Always {
};
(
Self,
PyBoolExpr(Box::new(BoolExpr::Always(argus_core::expr::Always { arg, interval }))),
PyBoolExpr(Box::new(BoolExpr::Always(argus::expr::Always { arg, interval }))),
)
}
}
@ -417,7 +393,7 @@ impl Eventually {
};
(
Self,
PyBoolExpr(Box::new(BoolExpr::Eventually(argus_core::expr::Eventually {
PyBoolExpr(Box::new(BoolExpr::Eventually(argus::expr::Eventually {
arg,
interval,
}))),
@ -443,11 +419,7 @@ impl Until {
};
(
Self,
PyBoolExpr(Box::new(BoolExpr::Until(argus_core::expr::Until {
lhs,
rhs,
interval,
}))),
PyBoolExpr(Box::new(BoolExpr::Until(argus::expr::Until { lhs, rhs, interval }))),
)
}
}

View file

@ -2,7 +2,7 @@ mod expr;
mod semantics;
mod signals;
use argus_core::ArgusError;
use argus::Error as ArgusError;
use pyo3::exceptions::{PyKeyError, PyRuntimeError, PyTypeError, PyValueError};
use pyo3::prelude::*;
use pyo3::types::{PyBool, PyFloat, PyInt, PyType};
@ -12,7 +12,7 @@ struct PyArgusError(ArgusError);
impl From<PyArgusError> for PyErr {
fn from(value: PyArgusError) -> Self {
use argus_core::Error::*;
use argus::Error::*;
match value.0 {
err @ (IncompleteArgs | InvalidOperation | IdentifierRedeclaration | InvalidInterval { reason: _ }) => {
PyValueError::new_err(err.to_string())

View file

@ -1,7 +1,6 @@
use std::collections::HashMap;
use argus_core::signals::{AnySignal, Signal};
use argus_semantics::{BooleanSemantics, QuantitativeSemantics, Trace};
use argus::{AnySignal, BooleanSemantics, QuantitativeSemantics, Signal, Trace};
use pyo3::exceptions::PyTypeError;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyString};

View file

@ -1,5 +1,5 @@
use argus_core::signals::interpolation::Linear;
use argus_core::signals::Signal;
use argus::signals::interpolation::Linear;
use argus::signals::Signal;
use pyo3::prelude::*;
use pyo3::types::PyType;