Skip to content

Commit

Permalink
pyo3
Browse files Browse the repository at this point in the history
  • Loading branch information
WT-MM committed Dec 16, 2024
1 parent 2573d3c commit 55d160e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions actuator/bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<ErrReportWrapper> for PyErr {
fn from(err: ErrReportWrapper) -> PyErr {
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(err.0.to_string())
}
}

#[pyfunction]
#[gen_stub_pyfunction]
fn get_version() -> String {
Expand Down Expand Up @@ -287,12 +299,14 @@ impl From<eyre::Report> 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::<PyRobstrideActuator>())?;
m.add("PyRobstrideActuatorCommand", py.get_type::<PyRobstrideActuatorCommand>())?;
m.add("PyRobstrideConfigureRequest", py.get_type::<PyRobstrideConfigureRequest>())?;
m.add("PyRobstrideActuatorState", py.get_type::<PyRobstrideActuatorState>())?;
m.add("PyRobstrideActuatorConfig", py.get_type::<PyRobstrideActuatorConfig>())?;
fn robstride_bindings(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(get_version))?;
m.add_class::<PyRobstrideActuator>()?;
m.add_class::<PyRobstrideActuatorCommand>()?;
m.add_class::<PyRobstrideConfigureRequest>()?;
m.add_class::<PyRobstrideActuatorState>()?;
m.add_class::<PyRobstrideActuatorConfig>()?;
Ok(())
}

define_stub_info_gatherer!(robstride_bindings);

0 comments on commit 55d160e

Please sign in to comment.