Browse Source

Merge pull request #547 from EricLBuehler/proc_macro_dir

Derive `__dir__`, `__str__`, `__repr__` with a proc macro crate
tags/v0.3.5
Haixuan Xavier Tao GitHub 1 year ago
parent
commit
04b845ad72
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
7 changed files with 310 additions and 276 deletions
  1. +290
    -269
      Cargo.lock
  2. +1
    -1
      Cargo.toml
  3. +3
    -1
      apis/python/node/Cargo.toml
  4. +3
    -1
      apis/python/node/src/lib.rs
  5. +2
    -0
      libraries/extensions/ros2-bridge/python/Cargo.toml
  6. +7
    -1
      libraries/extensions/ros2-bridge/python/src/lib.rs
  7. +4
    -3
      libraries/extensions/ros2-bridge/python/src/qos.rs

+ 290
- 269
Cargo.lock
File diff suppressed because it is too large
View File


+ 1
- 1
Cargo.toml View File

@@ -71,7 +71,7 @@ arrow = { version = "52" }
arrow-schema = { version = "52" }
arrow-data = { version = "52" }
arrow-array = { version = "52" }
pyo3 = "0.21"
pyo3 = { version = "0.21", features = ["eyre", "abi3-py37", "multiple-pymethods"] }
pythonize = "0.21"

[package]


+ 3
- 1
apis/python/node/Cargo.toml View File

@@ -16,7 +16,7 @@ telemetry = ["dora-runtime/telemetry"]
[dependencies]
dora-node-api = { workspace = true }
dora-operator-api-python = { workspace = true }
pyo3 = { workspace = true, features = ["eyre", "abi3-py37"] }
pyo3.workspace = true
eyre = "0.6"
serde_yaml = "0.8.23"
flume = "0.10.14"
@@ -25,6 +25,8 @@ arrow = { workspace = true, features = ["pyarrow"] }
pythonize = { workspace = true }
futures = "0.3.28"
dora-ros2-bridge-python = { workspace = true }
pyo3_special_method_derive = "0.3.0"
pyo3_special_method_derive_lib = "0.3.0"

[lib]
name = "dora"


+ 3
- 1
apis/python/node/src/lib.rs View File

@@ -12,6 +12,7 @@ use eyre::Context;
use futures::{Stream, StreamExt};
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict};
use pyo3_special_method_derive::Dir;

/// The custom node API lets you integrate `dora` into your application.
/// It allows you to retrieve input and send output in any fashion you want.
@@ -26,9 +27,10 @@ use pyo3::types::{PyBytes, PyDict};
///
/// :type node_id: str, optional
#[pyclass]
#[derive(Dir)]
pub struct Node {
events: Events,
node: DoraNode,
pub node: DoraNode,
}

#[pymethods]


+ 2
- 0
libraries/extensions/ros2-bridge/python/Cargo.toml View File

@@ -12,6 +12,8 @@ eyre = "0.6"
serde = "1.0.166"
arrow = { workspace = true, features = ["pyarrow"] }
futures = "0.3.28"
pyo3_special_method_derive = "0.3.0"
pyo3_special_method_derive_lib = "0.3.0"

[dev-dependencies]
serde_assert = "0.7.1"

+ 7
- 1
libraries/extensions/ros2-bridge/python/src/lib.rs View File

@@ -18,6 +18,7 @@ use pyo3::{
types::{PyAnyMethods, PyDict, PyList, PyModule, PyModuleMethods},
Bound, PyAny, PyObject, PyResult, Python,
};
use pyo3_special_method_derive::{Dict, Dir, Repr, Str};
use typed::{deserialize::StructDeserializer, TypeInfo, TypedValue};

pub mod qos;
@@ -45,6 +46,7 @@ pub mod typed;
/// :type ros_paths: typing.List[str], optional
///
#[pyclass]
#[derive(Str, Repr, Dir, Dict)]
pub struct Ros2Context {
context: ros2_client::Context,
messages: Arc<HashMap<String, HashMap<String, Message>>>,
@@ -147,6 +149,7 @@ impl Ros2Context {
/// See: https://github.com/jhelovuo/ros2-client/issues/4
///
#[pyclass]
#[derive(Str, Repr, Dir, Dict)]
pub struct Ros2Node {
node: ros2_client::Node,
messages: Arc<HashMap<String, HashMap<String, Message>>>,
@@ -251,7 +254,7 @@ impl Ros2Node {
/// ROS2 Node Options
/// :type rosout: bool, optional
///
#[derive(Debug, Clone, Default)]
#[derive(Clone, Default, Str, Repr, Dir, Dict)]
#[pyclass]
#[non_exhaustive]
pub struct Ros2NodeOptions {
@@ -281,6 +284,7 @@ impl From<Ros2NodeOptions> for ros2_client::NodeOptions {
/// - dora Ros2 bridge functionality is considered **unstable**. It may be changed
/// at any point without it being considered a breaking change.
#[pyclass]
#[derive(Str, Repr, Dir, Dict)]
#[non_exhaustive]
pub struct Ros2Topic {
topic: rustdds::Topic,
@@ -293,6 +297,7 @@ pub struct Ros2Topic {
/// - dora Ros2 bridge functionality is considered **unstable**. It may be changed
/// at any point without it being considered a breaking change.
#[pyclass]
#[derive(Str, Repr, Dir, Dict)]
#[non_exhaustive]
pub struct Ros2Publisher {
publisher: ros2_client::Publisher<TypedValue<'static>>,
@@ -363,6 +368,7 @@ impl Ros2Publisher {
/// - dora Ros2 bridge functionality is considered **unstable**. It may be changed
/// at any point without it being considered a breaking change.
#[pyclass]
#[derive(Str, Repr, Dir, Dict)]
#[non_exhaustive]
pub struct Ros2Subscription {
deserializer: StructDeserializer<'static>,


+ 4
- 3
libraries/extensions/ros2-bridge/python/src/qos.rs View File

@@ -1,5 +1,6 @@
use ::dora_ros2_bridge::rustdds::{self, policy};
use pyo3::prelude::{pyclass, pymethods};
use pyo3_special_method_derive::{Dict, Dir, Repr, Str};

/// ROS2 QoS Policy
///
@@ -12,7 +13,7 @@ use pyo3::prelude::{pyclass, pymethods};
/// :type keep_last: int, optional
/// :rtype: dora.Ros2QoSPolicies
///
#[derive(Debug, Clone)]
#[derive(Clone, Str, Repr, Dir, Dict)]
#[pyclass]
#[non_exhaustive]
pub struct Ros2QosPolicies {
@@ -77,7 +78,7 @@ impl From<Ros2QosPolicies> for rustdds::QosPolicies {
/// DDS 2.2.3.4 DURABILITY
///
/// :rtype: dora.Ros2Durability
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Str, Repr, Dir, Dict)]
#[pyclass]
pub enum Ros2Durability {
Volatile,
@@ -103,7 +104,7 @@ impl From<Ros2Durability> for policy::Durability {

/// DDS 2.2.3.11 LIVELINESS
/// :rtype: dora.Ros2Liveliness
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, PartialEq, Str, Repr, Dir, Dict)]
#[pyclass]
pub enum Ros2Liveliness {
Automatic,


Loading…
Cancel
Save