diff --git a/Cargo.toml b/Cargo.toml index 73da326..4d8382e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,45 +1,16 @@ -[package] -name = "smart-home-in-rust-with-home-assistant" -version = "0.2.0" -edition = "2021" +[workspace] +members = [ + "arbitrary-value", +resolver = "2" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -name = "smart_home_in_rust_with_home_assistant" -crate-type = ["cdylib"] - -[dependencies] +[workspace.dependencies] +backoff = "0.4.0" chrono = "0.4.40" chrono-tz = "0.10.1" -derive_more = { version = "2.0.1", features = [ - "display", - "from", - "into", - "try_from", - "try_into", -] } -ijson = "0.1.4" -itertools = "0.14.0" -pyo3 = { version = "0.24.0", features = [ - "auto-initialize", - "chrono", - "chrono-tz", -] } -pyo3-async-runtimes = { version = "0.24.0", features = ["tokio-runtime"] } -serde_json = "1.0.140" -shadow-rs = { version = "1.0.1", default-features = false } +deranged = "0.4.1" +derive_more = "2.0.1" snafu = "0.8.5" -strum = { version = "0.27.1", features = ["derive"] } -tokio = { version = "1.32.0", features = [ - "rt", - "rt-multi-thread", - "sync", - "time", -] } +tokio = "1.32.0" +pyo3 = "0.24.0" +pyo3-async-runtimes = "0.24.0" tracing = "0.1.37" -tracing-appender = "0.2.3" -tracing-subscriber = "0.3.17" -ulid = "1.2.0" - -[build-dependencies] -shadow-rs = "1.0.1" diff --git a/arbitrary-value/Cargo.toml b/arbitrary-value/Cargo.toml new file mode 100644 index 0000000..e95717a --- /dev/null +++ b/arbitrary-value/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "arbitrary-value" +version = "0.1.0" +edition = "2021" + +[features] +pyo3 = ["dep:pyo3"] + +[dependencies] +chrono = { workspace = true } +chrono-tz = { workspace = true } +derive_more = { workspace = true } +ijson = "0.1.4" +itertools = "0.14.0" +snafu = { workspace = true } + +pyo3 = { workspace = true, optional = true, features = ["chrono", "chrono-tz"] } diff --git a/src/arbitrary/arbitrary.rs b/arbitrary-value/src/arbitrary.rs similarity index 98% rename from src/arbitrary/arbitrary.rs rename to arbitrary-value/src/arbitrary.rs index 08900fa..63bc962 100644 --- a/src/arbitrary/arbitrary.rs +++ b/arbitrary-value/src/arbitrary.rs @@ -1,6 +1,7 @@ use chrono::DateTime; use chrono_tz::Tz; use ijson::{IArray, INumber, IObject, IString, IValue}; +#[cfg(feature = "pyo3")] use pyo3::{ exceptions::{PyTypeError, PyValueError}, prelude::*, @@ -71,6 +72,7 @@ impl From for IValue { } } +#[cfg(feature = "pyo3")] impl<'py> FromPyObject<'py> for Arbitrary { fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult { if let Ok(map_key) = ob.extract::() { @@ -91,6 +93,7 @@ impl<'py> FromPyObject<'py> for Arbitrary { } } +#[cfg(feature = "pyo3")] impl<'py> IntoPyObject<'py> for Arbitrary { type Target = PyAny; diff --git a/src/arbitrary/finite_f64.rs b/arbitrary-value/src/finite_f64.rs similarity index 80% rename from src/arbitrary/finite_f64.rs rename to arbitrary-value/src/finite_f64.rs index 3165820..8cce7b0 100644 --- a/src/arbitrary/finite_f64.rs +++ b/arbitrary-value/src/finite_f64.rs @@ -1,7 +1,7 @@ -use pyo3::IntoPyObject; use snafu::Snafu; -#[derive(Debug, Clone, derive_more::Into, IntoPyObject)] +#[cfg_attr(feature = "pyo3", derive(pyo3::IntoPyObject))] +#[derive(Debug, Clone, derive_more::Into)] pub struct FiniteF64(f64); #[derive(Debug, Snafu)] diff --git a/src/arbitrary/mod.rs b/arbitrary-value/src/lib.rs similarity index 75% rename from src/arbitrary/mod.rs rename to arbitrary-value/src/lib.rs index 0b69f7c..769a385 100644 --- a/src/arbitrary/mod.rs +++ b/arbitrary-value/src/lib.rs @@ -2,3 +2,5 @@ pub mod arbitrary; pub mod finite_f64; pub mod map; pub mod map_key; + +pub use arbitrary::*; diff --git a/arbitrary-value/src/map.rs b/arbitrary-value/src/map.rs new file mode 100644 index 0000000..9b9f3fb --- /dev/null +++ b/arbitrary-value/src/map.rs @@ -0,0 +1,7 @@ +use std::collections::BTreeMap; + +use super::{arbitrary::Arbitrary, map_key::MapKey}; + +#[cfg_attr(feature = "pyo3", derive(pyo3::FromPyObject, pyo3::IntoPyObject))] +#[derive(Debug, Clone, Default, derive_more::From, derive_more::Into)] +pub struct Map(pub BTreeMap); diff --git a/src/arbitrary/map_key.rs b/arbitrary-value/src/map_key.rs similarity index 97% rename from src/arbitrary/map_key.rs rename to arbitrary-value/src/map_key.rs index 3e71e4b..4f593f2 100644 --- a/src/arbitrary/map_key.rs +++ b/arbitrary-value/src/map_key.rs @@ -4,6 +4,7 @@ use chrono::DateTime; use chrono_tz::Tz; use ijson::IString; use itertools::Itertools; +#[cfg(feature = "pyo3")] use pyo3::{ exceptions::PyTypeError, prelude::*, @@ -41,6 +42,7 @@ impl Display for MapKey { } } +#[cfg(feature = "pyo3")] impl<'py> FromPyObject<'py> for MapKey { fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult { if let Ok(_none) = ob.downcast::() { @@ -62,6 +64,7 @@ impl<'py> FromPyObject<'py> for MapKey { } } +#[cfg(feature = "pyo3")] impl<'py> IntoPyObject<'py> for MapKey { type Target = PyAny; diff --git a/src/arbitrary/map.rs b/src/arbitrary/map.rs deleted file mode 100644 index a9018f7..0000000 --- a/src/arbitrary/map.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::collections::BTreeMap; - -use pyo3::prelude::*; - -use super::{arbitrary::Arbitrary, map_key::MapKey}; - -#[derive(Debug, Clone, Default, derive_more::From, derive_more::Into, IntoPyObject)] -pub struct Map(pub BTreeMap); - -impl<'py> FromPyObject<'py> for Map { - fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult { - let inner = ob.extract()?; - - Ok(Self(inner)) - } -}