Skip to content

Commit

Permalink
upgraded to 0.22 (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwsw authored Apr 17, 2024
1 parent b9dd23d commit f34c2f4
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ savant_core = { path = "savant_core" }
savant_core_py = { path = "savant_core_py" }

[workspace.package]
version = "0.2.24"
version = "0.2.25"
edition = "2021"
authors = ["Ivan Kudriavtsev <[email protected]>"]
description = "Savant Rust core functions library"
Expand Down
6 changes: 3 additions & 3 deletions savant_algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ savant_rs = { path = "../savant_python" }
parking_lot = "0.12"
anyhow = "1"
opentelemetry = "0.19"
numpy = {version = "0.19", features = ["nalgebra"]}
numpy = { version = "0.19", features = ["nalgebra"] }
nalgebra = "0.32"
ndarray = "0.15"
num-traits = "0.2"
Expand All @@ -29,11 +29,11 @@ log = "0.4"
crate-type = ["cdylib", "lib"]

[dependencies.pyo3]
version = "0.19"
version = "0.12"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

[build-dependencies]
pyo3-build-config = "0.19"
pyo3-build-config = "0.21"
10 changes: 5 additions & 5 deletions savant_core_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version.workspace = true
edition.workspace = true
authors.workspace = true
description.workspace = true
homepage.workspace = true
homepage.workspace = true
repository.workspace = true
readme.workspace = true
keywords.workspace = true
Expand All @@ -16,29 +16,29 @@ rust-version.workspace = true
crate-type = ["dylib"]

[dependencies]
savant_core = {workspace = true}
savant_core = { workspace = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0"
thiserror = "1.0"
geo = "0.26"
lazy_static = "1.4"
parking_lot = {version = "0.12", features = ["deadlock_detection"]}
parking_lot = { version = "0.12", features = ["deadlock_detection"] }
evalexpr = { version = "11", features = ["rand", "regex_support"] }
log = "0.4"
opentelemetry = "0.21"
colored = "2"
hashbrown = "0.14"

[dependencies.pyo3]
version = "0.20"
version = "0.21"

[dev-dependencies]
serial_test = "2.0"


[build-dependencies]
pyo3-build-config = "0.20"
pyo3-build-config = "0.21"
cbindgen = "0.24"

[package.metadata.maturin]
Expand Down
2 changes: 1 addition & 1 deletion savant_core_py/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub fn log_message_gil(
level: LogLevel,
target: &str,
message: &str,
params: Option<&PyDict>,
params: Option<&Bound<'_, PyDict>>,
no_gil: bool,
) {
let params: Option<_> = params.map(|params| {
Expand Down
10 changes: 5 additions & 5 deletions savant_core_py/src/match_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl FloatExpression {
///
#[staticmethod]
#[pyo3(signature = (*list))]
fn one_of(list: &PyTuple) -> FloatExpression {
fn one_of(list: &Bound<'_, PyTuple>) -> FloatExpression {
let mut vals = Vec::with_capacity(list.len());
for arg in list {
let v = arg
Expand Down Expand Up @@ -494,7 +494,7 @@ impl IntExpression {
///
#[staticmethod]
#[pyo3(signature = (*list))]
fn one_of(list: &PyTuple) -> IntExpression {
fn one_of(list: &Bound<'_, PyTuple>) -> IntExpression {
let mut vals = Vec::with_capacity(list.len());
for arg in list {
let v = arg
Expand Down Expand Up @@ -711,7 +711,7 @@ impl StringExpression {
///
#[staticmethod]
#[pyo3(signature = (*list))]
fn one_of(list: &PyTuple) -> StringExpression {
fn one_of(list: &Bound<'_, PyTuple>) -> StringExpression {
let mut vals = Vec::with_capacity(list.len());
for arg in list {
let v = arg
Expand Down Expand Up @@ -772,7 +772,7 @@ impl MatchQuery {
///
#[staticmethod]
#[pyo3(signature = (*list))]
fn and_(list: &PyTuple) -> MatchQuery {
fn and_(list: &Bound<'_, PyTuple>) -> MatchQuery {
let mut v = Vec::with_capacity(list.len());
for arg in list {
let q = arg
Expand Down Expand Up @@ -813,7 +813,7 @@ impl MatchQuery {
///
#[staticmethod]
#[pyo3(signature = (*list))]
fn or_(list: &PyTuple) -> MatchQuery {
fn or_(list: &Bound<'_, PyTuple>) -> MatchQuery {
let mut v = Vec::with_capacity(list.len());
for arg in list {
let q = arg
Expand Down
8 changes: 4 additions & 4 deletions savant_core_py/src/primitives/attribute_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::primitives::segment::Intersection;
use crate::primitives::{Point, PolygonalArea, RBBox};
use crate::with_gil;
use pyo3::exceptions::{PyIndexError, PyValueError};
use pyo3::types::PyBytes;
use pyo3::{pyclass, pymethods, Py, PyAny, PyObject, PyResult};
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyclass, pymethods, Bound, Py, PyAny, PyObject, PyResult};
use savant_core::primitives::any_object::AnyObject;
use savant_core::primitives::attribute_value::AttributeValueVariant;
use savant_core::primitives::rust;
Expand Down Expand Up @@ -169,7 +169,7 @@ impl AttributeValue {
///
#[staticmethod]
#[pyo3(signature = (dims, blob, confidence = None))]
pub fn bytes(dims: Vec<i64>, blob: &PyBytes, confidence: Option<f32>) -> Self {
pub fn bytes(dims: Vec<i64>, blob: &Bound<'_, PyBytes>, confidence: Option<f32>) -> Self {
Self(rust::AttributeValue {
confidence,
value: AttributeValueVariant::Bytes(dims, blob.as_bytes().to_vec()),
Expand Down Expand Up @@ -520,7 +520,7 @@ impl AttributeValue {
match &self.0.value {
AttributeValueVariant::Bytes(dims, bytes) => Some((
dims.clone(),
with_gil!(|py| PyObject::from(PyBytes::new(py, bytes))),
with_gil!(|py| PyObject::from(PyBytes::new_bound(py, bytes))),
)),
_ => None,
}
Expand Down
8 changes: 4 additions & 4 deletions savant_core_py/src/primitives/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::primitives::object::BorrowedVideoObject;
use crate::primitives::objects_view::VideoObjectsView;
use crate::{release_gil, with_gil};
use pyo3::exceptions::PyRuntimeError;
use pyo3::types::PyBytes;
use pyo3::{pyclass, pymethods, PyObject, PyResult};
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyclass, pymethods, Bound, PyObject, PyResult};
use savant_core::primitives::rust;
use savant_core::protobuf::{from_pb, ToProtobuf};
use std::collections::HashMap;
Expand Down Expand Up @@ -80,15 +80,15 @@ impl VideoFrameBatch {
})
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}

#[staticmethod]
#[pyo3(name = "from_protobuf")]
#[pyo3(signature = (bytes, no_gil = true))]
fn from_protobuf_gil(bytes: &PyBytes, no_gil: bool) -> PyResult<Self> {
fn from_protobuf_gil(bytes: &Bound<'_, PyBytes>, no_gil: bool) -> PyResult<Self> {
let bytes = bytes.as_bytes();
release_gil!(no_gil, || {
let obj =
Expand Down
12 changes: 6 additions & 6 deletions savant_core_py/src/primitives/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::primitives::objects_view::VideoObjectsView;
use crate::release_gil;
use crate::with_gil;
use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::types::PyBytes;
use pyo3::{pyclass, pymethods, Py, PyAny, PyObject, PyResult};
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyclass, pymethods, Bound, Py, PyAny, PyObject, PyResult};
use savant_core::json_api::ToSerdeJsonValue;
use savant_core::primitives::object::ObjectOperations;
use savant_core::primitives::{rust, WithAttributes};
Expand Down Expand Up @@ -96,7 +96,7 @@ impl VideoFrameContent {
}

#[staticmethod]
pub fn internal(data: &PyBytes) -> Self {
pub fn internal(data: &Bound<'_, PyBytes>) -> Self {
let bytes = data.as_bytes();
Self(rust::VideoFrameContent::Internal(bytes.to_vec()))
}
Expand Down Expand Up @@ -135,7 +135,7 @@ impl VideoFrameContent {
match &self.0 {
rust::VideoFrameContent::Internal(data) => {
with_gil!(|py| {
let bytes = PyBytes::new_with(py, data.len(), |b: &mut [u8]| {
let bytes = PyBytes::new_bound_with(py, data.len(), |b: &mut [u8]| {
b.copy_from_slice(data);
Ok(())
})?;
Expand Down Expand Up @@ -1107,15 +1107,15 @@ impl VideoFrame {
})
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}

#[staticmethod]
#[pyo3(name = "from_protobuf")]
#[pyo3(signature = (bytes, no_gil = true))]
fn from_protobuf_gil(bytes: &PyBytes, no_gil: bool) -> PyResult<Self> {
fn from_protobuf_gil(bytes: &Bound<'_, PyBytes>, no_gil: bool) -> PyResult<Self> {
let bytes = bytes.as_bytes();
release_gil!(no_gil, || {
let obj = from_pb::<savant_core::protobuf::VideoFrame, rust::VideoFrameProxy>(bytes)
Expand Down
4 changes: 2 additions & 2 deletions savant_core_py/src/primitives/frame_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ impl VideoFrameUpdate {
})
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}

#[staticmethod]
#[pyo3(name = "from_protobuf")]
#[pyo3(signature = (bytes, no_gil = true))]
fn from_protobuf_gil(bytes: &PyBytes, no_gil: bool) -> PyResult<Self> {
fn from_protobuf_gil(bytes: &Bound<'_, PyBytes>, no_gil: bool) -> PyResult<Self> {
let bytes = bytes.as_bytes();
release_gil!(no_gil, || {
let obj =
Expand Down
6 changes: 3 additions & 3 deletions savant_core_py/src/primitives/message/loader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::primitives::message::Message;
use crate::release_gil;
use crate::utils::byte_buffer::ByteBuffer;
use pyo3::pyfunction;
use pyo3::types::PyBytes;
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyfunction, Bound};

/// Loads a message from a byte array. The function is optionally GIL-free.
///
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn load_message_from_bytebuffer_gil(buffer: &ByteBuffer, no_gil: bool) -> Me
#[pyfunction]
#[pyo3(name = "load_message_from_bytes")]
#[pyo3(signature = (buffer, no_gil = true))]
pub fn load_message_from_bytes_gil(buffer: &PyBytes, no_gil: bool) -> Message {
pub fn load_message_from_bytes_gil(buffer: &Bound<'_, PyBytes>, no_gil: bool) -> Message {
let bytes = buffer.as_bytes();
release_gil!(no_gil, || Message(savant_core::message::load_message(
bytes
Expand Down
2 changes: 1 addition & 1 deletion savant_core_py/src/primitives/message/saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn save_message_to_bytes_gil(message: &Message, no_gil: bool) -> PyResult<Py
let bytes = release_gil!(no_gil, || savant_core::message::save_message(&message.0))
.map_err(|e| pyo3::exceptions::PyException::new_err(format!("{:?}", e)))?;
with_gil!(|py| {
let bytes = PyBytes::new_with(py, bytes.len(), |b: &mut [u8]| {
let bytes = PyBytes::new_bound_with(py, bytes.len(), |b: &mut [u8]| {
b.copy_from_slice(&bytes);
Ok(())
})?;
Expand Down
10 changes: 5 additions & 5 deletions savant_core_py/src/primitives/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::primitives::bbox::VideoObjectBBoxTransformation;
use crate::primitives::{Attribute, RBBox};
use crate::{release_gil, with_gil};
use pyo3::exceptions::PyRuntimeError;
use pyo3::types::PyBytes;
use pyo3::{pyclass, pymethods, PyObject, PyResult};
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyclass, pymethods, Bound, PyObject, PyResult};
use savant_core::json_api::ToSerdeJsonValue;
use savant_core::primitives::object::{ObjectAccess, ObjectOperations};
use savant_core::primitives::{rust, WithAttributes};
Expand Down Expand Up @@ -75,15 +75,15 @@ impl VideoObject {
))
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}

#[staticmethod]
#[pyo3(name = "from_protobuf")]
#[pyo3(signature = (bytes, no_gil = true))]
fn from_protobuf_gil(bytes: &PyBytes, no_gil: bool) -> PyResult<Self> {
fn from_protobuf_gil(bytes: &Bound<'_, PyBytes>, no_gil: bool) -> PyResult<Self> {
let bytes = bytes.as_bytes();
release_gil!(no_gil, || {
let obj = from_pb::<savant_core::protobuf::VideoObject, rust::VideoObject>(bytes)
Expand Down Expand Up @@ -541,7 +541,7 @@ impl BorrowedVideoObject {
))
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}
Expand Down
8 changes: 4 additions & 4 deletions savant_core_py/src/primitives/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::primitives::attribute_value::AttributeValue;
use crate::primitives::message::Message;
use crate::{release_gil, with_gil};
use pyo3::exceptions::PyRuntimeError;
use pyo3::types::PyBytes;
use pyo3::{pyclass, pymethods, Py, PyAny, PyObject, PyResult};
use pyo3::types::{PyBytes, PyBytesMethods};
use pyo3::{pyclass, pymethods, Bound, Py, PyAny, PyObject, PyResult};
use savant_core::json_api::ToSerdeJsonValue;
use savant_core::primitives::rust as rust_primitives;
use savant_core::primitives::{rust, WithAttributes};
Expand Down Expand Up @@ -203,15 +203,15 @@ impl UserData {
})
})?;
with_gil!(|py| {
let bytes = PyBytes::new(py, &bytes);
let bytes = PyBytes::new_bound(py, &bytes);
Ok(PyObject::from(bytes))
})
}

#[staticmethod]
#[pyo3(name = "from_protobuf")]
#[pyo3(signature = (bytes, no_gil = true))]
fn from_protobuf_gil(bytes: &PyBytes, no_gil: bool) -> PyResult<Self> {
fn from_protobuf_gil(bytes: &Bound<'_, PyBytes>, no_gil: bool) -> PyResult<Self> {
let bytes = bytes.as_bytes();
release_gil!(no_gil, || {
let obj =
Expand Down
4 changes: 2 additions & 2 deletions savant_core_py/src/utils/byte_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct ByteBuffer {
#[pymethods]
impl ByteBuffer {
#[new]
fn create(v: &PyBytes, checksum: Option<u32>) -> PyResult<Self> {
fn create(v: &Bound<'_, PyBytes>, checksum: Option<u32>) -> PyResult<Self> {
Ok(Self::new(v.as_bytes().to_vec(), checksum))
}

Expand Down Expand Up @@ -80,7 +80,7 @@ impl ByteBuffer {
#[pyo3(name = "bytes")]
pub fn bytes_py(&self) -> PyObject {
with_gil!(|py| {
let bytes = PyBytes::new(py, self.inner.as_slice());
let bytes = PyBytes::new_bound(py, self.inner.as_slice());
PyObject::from(bytes)
})
}
Expand Down
Loading

0 comments on commit f34c2f4

Please sign in to comment.