From 55d160e2f82d8d10536aa05b08bd8b122b9ffa32 Mon Sep 17 00:00:00 2001 From: Wesley Maa Date: Sun, 15 Dec 2024 18:45:25 -0800 Subject: [PATCH] pyo3 --- actuator/bindings/src/lib.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/actuator/bindings/src/lib.rs b/actuator/bindings/src/lib.rs index 1a696b6..328ad24 100644 --- a/actuator/bindings/src/lib.rs +++ b/actuator/bindings/src/lib.rs @@ -1,11 +1,23 @@ use pyo3::prelude::*; use pyo3_stub_gen::define_stub_info_gatherer; use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pyfunction, gen_stub_pymethods};use robstride::{CH341Transport, ControlConfig, SocketCanTransport, Supervisor, TransportType}; +use robstride::{ + ActuatorType, CH341Transport, ControlConfig, SocketCanTransport, + Supervisor, TransportType, ActuatorConfiguration +}; use std::sync::Arc; use tokio::sync::Mutex; use std::time::Duration; use tokio::runtime::Runtime; +struct ErrReportWrapper(eyre::Report); + +impl From for PyErr { + fn from(err: ErrReportWrapper) -> PyErr { + PyErr::new::(err.0.to_string()) + } +} + #[pyfunction] #[gen_stub_pyfunction] fn get_version() -> String { @@ -287,12 +299,14 @@ impl From for PyErr { } #[pymodule] -fn robstride_bindings(py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(get_version, m)?)?; - m.add("PyRobstrideActuator", py.get_type::())?; - m.add("PyRobstrideActuatorCommand", py.get_type::())?; - m.add("PyRobstrideConfigureRequest", py.get_type::())?; - m.add("PyRobstrideActuatorState", py.get_type::())?; - m.add("PyRobstrideActuatorConfig", py.get_type::())?; +fn robstride_bindings(_py: Python<'_>, m: &PyModule) -> PyResult<()> { + m.add_wrapped(wrap_pyfunction!(get_version))?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; + m.add_class::()?; Ok(()) } + +define_stub_info_gatherer!(robstride_bindings);