From 8e2da6c1732c498253239cbced1096535919e82d Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Mon, 17 Feb 2025 20:10:40 +0100 Subject: [PATCH 1/5] Update pyo3 to 0.23.4 --- Cargo.toml | 8 +++--- profiling/Cargo.toml | 4 +-- src/lib.rs | 64 ++++++++++++++++++++++---------------------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 554347a..c8087ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,11 +13,11 @@ name = "libipld" crate-type = ["rlib", "cdylib"] [dependencies] -pyo3 = { version = "0.22.5", features = ["generate-import-lib", "anyhow"] } -python3-dll-a = "0.2.10" -anyhow = "1.0.75" +pyo3 = { version = "0.23.4", features = ["generate-import-lib", "anyhow"] } +python3-dll-a = "0.2.13" +anyhow = "1.0.95" libipld = { version = "0.16.0", features = ["dag-cbor"] } -multibase = "0.9" +multibase = "0.9.1" byteorder = "1.5.0" multihash = "0.18.1" diff --git a/profiling/Cargo.toml b/profiling/Cargo.toml index 3b7ab56..884e4f7 100644 --- a/profiling/Cargo.toml +++ b/profiling/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" libipld = { path = ".." } structopt = "0.3.26" -clap = "4.5.1" +clap = "4.5.29" [dependencies.pyo3] -version = "0.22.2" +version = "0.23.4" diff --git a/src/lib.rs b/src/lib.rs index c49d5ac..290eb2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,25 +7,24 @@ use ::libipld::cid::{Cid, Error as CidError, Result as CidResult, Version}; use anyhow::{anyhow, Result}; use byteorder::{BigEndian, ByteOrder}; use multihash::Multihash; -use pyo3::{ffi, prelude::*, types::*, PyObject, Python}; -use pyo3::conversion::ToPyObject; +use pyo3::{ffi, prelude::*, types::*, BoundObject, PyObject, Python}; use pyo3::pybacked::PyBackedStr; fn cid_hash_to_pydict<'py>(py: Python<'py>, cid: &Cid) -> Bound<'py, PyDict> { let hash = cid.hash(); - let dict_obj = PyDict::new_bound(py); + let dict_obj = PyDict::new(py); dict_obj.set_item("code", hash.code()).unwrap(); dict_obj.set_item("size", hash.size()).unwrap(); dict_obj - .set_item("digest", PyBytes::new_bound(py, &hash.digest())) + .set_item("digest", PyBytes::new(py, &hash.digest())) .unwrap(); dict_obj } fn cid_to_pydict<'py>(py: Python<'py>, cid: &Cid) -> Bound<'py, PyDict> { - let dict_obj = PyDict::new_bound(py); + let dict_obj = PyDict::new(py); dict_obj.set_item("version", cid.version() as u64).unwrap(); dict_obj.set_item("codec", cid.codec()).unwrap(); @@ -122,15 +121,15 @@ fn decode_dag_cbor_to_pyobject( let major = decode::read_major(r)?; Ok(match major.kind() { - MajorKind::UnsignedInt => decode::read_uint(r, major)?.to_object(py), - MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i64).to_object(py), + MajorKind::UnsignedInt => decode::read_uint(r, major)?.into_pyobject(py)?.into(), + MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i64).into_pyobject(py)?.into(), MajorKind::ByteString => { let len = decode::read_uint(r, major)?; - PyBytes::new_bound(py, &decode::read_bytes(r, len)?).to_object(py) + PyBytes::new(py, &decode::read_bytes(r, len)?).into_pyobject(py)?.into() } MajorKind::TextString => { let len = decode::read_uint(r, major)?; - string_new_bound(py, &decode::read_bytes(r, len)?).to_object(py) + string_new_bound(py, &decode::read_bytes(r, len)?).into_pyobject(py)?.into() } MajorKind::Array => { let len: ffi::Py_ssize_t = decode_len(decode::read_uint(r, major)?)?.try_into()?; @@ -143,12 +142,12 @@ fn decode_dag_cbor_to_pyobject( } let list: Bound<'_, PyList> = Bound::from_owned_ptr(py, ptr).downcast_into_unchecked(); - list.to_object(py) + list.into_pyobject(py)?.into() } } MajorKind::Map => { let len = decode_len(decode::read_uint(r, major)?)?; - let dict = PyDict::new_bound(py); + let dict = PyDict::new(py); let mut prev_key: Option> = None; for _ in 0..len { @@ -168,14 +167,14 @@ fn decode_dag_cbor_to_pyobject( } } - let key_py = string_new_bound(py, key.as_slice()).to_object(py); + let key_py = string_new_bound(py, key.as_slice()).into_pyobject(py)?; prev_key = Some(key); let value_py = decode_dag_cbor_to_pyobject(py, r, depth + 1)?; dict.set_item(key_py, value_py)?; } - dict.to_object(py) + dict.into_pyobject(py)?.into() } MajorKind::Tag => { let value = decode::read_uint(r, major)?; @@ -185,14 +184,15 @@ fn decode_dag_cbor_to_pyobject( // FIXME(MarshalX): to_bytes allocates let cid = decode::read_link(r)?.to_bytes(); - PyBytes::new_bound(py, &cid).to_object(py) + PyBytes::new(py, &cid).into_pyobject(py)?.into() } MajorKind::Other => match major { - cbor::FALSE => false.to_object(py), - cbor::TRUE => true.to_object(py), + // FIXME(MarshalX): should be more clear for bool? + cbor::FALSE => false.into_pyobject(py)?.into_any().unbind(), + cbor::TRUE => true.into_pyobject(py)?.into_any().unbind(), cbor::NULL => py.None(), - cbor::F32 => decode::read_f32(r)?.to_object(py), - cbor::F64 => decode::read_f64(r)?.to_object(py), + cbor::F32 => decode::read_f32(r)?.into_pyobject(py)?.into(), + cbor::F64 => decode::read_f64(r)?.into_pyobject(py)?.into(), _ => return Err(anyhow!("Unsupported major type".to_string())), }, }) @@ -311,7 +311,7 @@ fn encode_dag_cbor_from_pyobject<'py, W: Write>( #[pyfunction] fn decode_dag_cbor_multi<'py>(py: Python<'py>, data: &[u8]) -> PyResult> { let mut reader = BufReader::new(Cursor::new(data)); - let decoded_parts = PyList::empty_bound(py); + let decoded_parts = PyList::empty(py); loop { let py_object = decode_dag_cbor_to_pyobject(py, &mut reader, 0); @@ -420,7 +420,7 @@ pub fn decode_car<'py>(py: Python<'py>, data: &[u8]) -> PyResult<(PyObject, Boun // FIXME (MarshalX): we are not verifying if the roots are valid CIDs - let parsed_blocks = PyDict::new_bound(py); + let parsed_blocks = PyDict::new(py); loop { if let Err(_) = read_u64_leb128(buf) { @@ -452,7 +452,7 @@ pub fn decode_car<'py>(py: Python<'py>, data: &[u8]) -> PyResult<(PyObject, Boun }; // FIXME(MarshalX): to_bytes allocates - let key = PyBytes::new_bound(py, &cid.to_bytes()).to_object(py); + let key = PyBytes::new(py, &cid.to_bytes()).into_pyobject(py)?; parsed_blocks.set_item(key, block)?; } @@ -494,7 +494,7 @@ pub fn encode_dag_cbor<'py>( if let Err(e) = buf.flush() { return Err(get_err("Failed to flush buffer", e.to_string())); } - Ok(PyBytes::new_bound(py, &buf.get_ref())) + Ok(PyBytes::new(py, &buf.get_ref())) } fn get_cid_from_py_any<'py>(data: &Bound) -> PyResult { @@ -522,14 +522,14 @@ fn decode_cid<'py>(py: Python<'py>, data: &Bound) -> PyResult(py: Python<'py>, data: &Bound) -> PyResult> { - Ok(PyString::new_bound(py, get_cid_from_py_any(data)?.to_string().as_str())) + Ok(PyString::new(py, get_cid_from_py_any(data)?.to_string().as_str())) } #[pyfunction] fn decode_multibase<'py>(py: Python<'py>, data: &str) -> PyResult<(char, Bound<'py, PyBytes>)> { let base = multibase::decode(data); if let Ok((base, data)) = base { - Ok((base.code(), PyBytes::new_bound(py, &data))) + Ok((base.code(), PyBytes::new(py, &data))) } else { Err(get_err( "Failed to decode multibase", @@ -558,17 +558,17 @@ fn get_err(msg: &str, err: String) -> PyErr { #[pymodule] fn libipld(m: &Bound<'_, PyModule>) -> PyResult<()> { - m.add_function(wrap_pyfunction_bound!(decode_cid, m)?)?; - m.add_function(wrap_pyfunction_bound!(encode_cid, m)?)?; + m.add_function(wrap_pyfunction!(decode_cid, m)?)?; + m.add_function(wrap_pyfunction!(encode_cid, m)?)?; - m.add_function(wrap_pyfunction_bound!(decode_car, m)?)?; + m.add_function(wrap_pyfunction!(decode_car, m)?)?; - m.add_function(wrap_pyfunction_bound!(decode_dag_cbor, m)?)?; - m.add_function(wrap_pyfunction_bound!(decode_dag_cbor_multi, m)?)?; - m.add_function(wrap_pyfunction_bound!(encode_dag_cbor, m)?)?; + m.add_function(wrap_pyfunction!(decode_dag_cbor, m)?)?; + m.add_function(wrap_pyfunction!(decode_dag_cbor_multi, m)?)?; + m.add_function(wrap_pyfunction!(encode_dag_cbor, m)?)?; - m.add_function(wrap_pyfunction_bound!(decode_multibase, m)?)?; - m.add_function(wrap_pyfunction_bound!(encode_multibase, m)?)?; + m.add_function(wrap_pyfunction!(decode_multibase, m)?)?; + m.add_function(wrap_pyfunction!(encode_multibase, m)?)?; Ok(()) } From 42787dd967cf2db84317edae2025b69d944e8228 Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Mon, 17 Feb 2025 20:21:25 +0100 Subject: [PATCH 2/5] bump version; trigger CI test release --- .github/workflows/release.yml | 1 + Cargo.toml | 2 +- LICENSE | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 457ec7d..5d55db2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - update-pyo3 tags: - 'v*.*.*' workflow_dispatch: diff --git a/Cargo.toml b/Cargo.toml index c8087ac..b356c6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libipld" -version = "3.0.0" +version = "3.0.1" edition = "2021" license = "MIT" description = "Python binding to the Rust IPLD library" diff --git a/LICENSE b/LICENSE index be72a82..329ee9b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Ilya Siamionau +Copyright (c) 2025 Ilya Siamionau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From cdfadfe40c78b5f6032e1af4915ede3bc51bf756 Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Mon, 17 Feb 2025 20:25:54 +0100 Subject: [PATCH 3/5] remove pypy3.8 support --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d55db2..72406e7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,11 +37,11 @@ jobs: - os: macos target: x86_64 - interpreter: pypy3.8 pypy3.9 pypy3.10 + interpreter: pypy3.9 pypy3.10 - os: macos target: aarch64 # actions/setup-python@v5 does not support 3.8 and 3.9 on arm64 - interpreter: 3.8 3.9 pypy3.8 pypy3.9 pypy3.10 + interpreter: 3.8 3.9 pypy3.9 pypy3.10 - os: ubuntu target: x86_64 @@ -91,7 +91,7 @@ jobs: target: ${{ matrix.target }} manylinux: ${{ matrix.manylinux || 'auto' }} container: ${{ matrix.container }} - args: --release --out dist --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }} + args: --release --out dist --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }} rust-toolchain: 1.76.0 docker-options: -e CI From 1cf494d5fb2bfdbe86c9b9fd4e120ec3104e9cf7 Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Tue, 18 Feb 2025 10:40:22 +0100 Subject: [PATCH 4/5] use macOS runner 13 instead of 12 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 72406e7..739fdbc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,7 +109,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-latest, windows-latest, macos-12, macos-14 ] + os: [ ubuntu-latest, windows-latest, macos-13, macos-14 ] interpreter: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13' ] exclude: # actions/setup-python@v5 does not support 3.8 and 3.9 on arm64 From 5e6265ed8c6bd967cbe3cd852ec520d87a60cea4 Mon Sep 17 00:00:00 2001 From: "Ilya (Marshal)" Date: Tue, 18 Feb 2025 10:59:12 +0100 Subject: [PATCH 5/5] remove test CI trigger --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 739fdbc..682870c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - update-pyo3 tags: - 'v*.*.*' workflow_dispatch: