From 97236e5d4613d2ded8e79485441381482fc34fb5 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Sat, 22 Feb 2025 15:32:45 -0700 Subject: [PATCH 1/2] Update to PyO3 0.22 --- Cargo.lock | 152 +++------------------------- Cargo.toml | 2 +- rust-ext/src/compression_chunker.rs | 18 ++-- rust-ext/src/compression_writer.rs | 1 + rust-ext/src/compressionobj.rs | 1 + rust-ext/src/compressor_multi.rs | 2 +- rust-ext/src/decompressionobj.rs | 1 + rust-ext/src/decompressor_multi.rs | 2 +- 8 files changed, 29 insertions(+), 150 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 648f7d0c..c01562b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "autocfg" @@ -8,12 +8,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "cc" version = "1.0.98" @@ -64,9 +58,9 @@ checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" @@ -95,16 +89,6 @@ version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memoffset" version = "0.9.1" @@ -130,29 +114,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pkg-config" version = "0.3.30" @@ -176,15 +137,15 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -194,9 +155,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" dependencies = [ "once_cell", "target-lexicon", @@ -204,9 +165,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" dependencies = [ "libc", "pyo3-build-config", @@ -214,9 +175,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -226,9 +187,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.22.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" dependencies = [ "heck", "proc-macro2", @@ -278,27 +239,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" -dependencies = [ - "bitflags", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "smallvec" -version = "1.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" - [[package]] name = "syn" version = "2.0.66" @@ -328,70 +268,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - [[package]] name = "zstd-safe" version = "7.1.0" diff --git a/Cargo.toml b/Cargo.toml index 445183fc..89cb0df1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,5 +26,5 @@ version = "2.0.10+zstd.1.5.6" features = ["experimental", "legacy", "zstdmt"] [dependencies.pyo3] -version = "0.21.2" +version = "0.22.6" features = ["extension-module"] diff --git a/rust-ext/src/compression_chunker.rs b/rust-ext/src/compression_chunker.rs index e9d4744a..6ca072d8 100644 --- a/rust-ext/src/compression_chunker.rs +++ b/rust-ext/src/compression_chunker.rs @@ -85,7 +85,7 @@ impl ZstdCompressionChunker { let source = make_in_buffer_source(py, data, zstd_safe::CCtx::in_size())?; - let it = Py::new( + let it = Bound::new( py, ZstdCompressionChunkerIterator { cctx: self.cctx.clone(), @@ -96,9 +96,9 @@ impl ZstdCompressionChunker { }, )?; - self.iterator = Some(it.clone()); + self.iterator = Some(it.clone().unbind()); - Ok(it) + Ok(it.unbind()) } fn flush<'p>(&mut self, py: Python<'p>) -> PyResult> { @@ -119,7 +119,7 @@ impl ZstdCompressionChunker { let source = make_in_buffer_source(py, &PyBytes::new_bound(py, &[]), zstd_safe::CCtx::in_size())?; - let it = Py::new( + let it = Bound::new( py, ZstdCompressionChunkerIterator { cctx: self.cctx.clone(), @@ -130,9 +130,9 @@ impl ZstdCompressionChunker { }, )?; - self.iterator = Some(it.clone()); + self.iterator = Some(it.clone().unbind()); - Ok(it) + Ok(it.unbind()) } fn finish<'p>(&mut self, py: Python<'p>) -> PyResult> { @@ -153,7 +153,7 @@ impl ZstdCompressionChunker { let source = make_in_buffer_source(py, &PyBytes::new_bound(py, &[]), zstd_safe::CCtx::in_size())?; - let it = Py::new( + let it = Bound::new( py, ZstdCompressionChunkerIterator { cctx: self.cctx.clone(), @@ -164,9 +164,9 @@ impl ZstdCompressionChunker { }, )?; - self.iterator = Some(it.clone()); + self.iterator = Some(it.clone().unbind()); - Ok(it) + Ok(it.unbind()) } } diff --git a/rust-ext/src/compression_writer.rs b/rust-ext/src/compression_writer.rs index d64658d9..a2475538 100644 --- a/rust-ext/src/compression_writer.rs +++ b/rust-ext/src/compression_writer.rs @@ -184,6 +184,7 @@ impl ZstdCompressionWriter { false } + #[pyo3(signature = (size=None))] #[allow(unused_variables)] fn truncate(&self, py: Python, size: Option<&Bound<'_, PyAny>>) -> PyResult<()> { let io = py.import_bound("io")?; diff --git a/rust-ext/src/compressionobj.rs b/rust-ext/src/compressionobj.rs index 6926da49..90dc0e9c 100644 --- a/rust-ext/src/compressionobj.rs +++ b/rust-ext/src/compressionobj.rs @@ -66,6 +66,7 @@ impl ZstdCompressionObj { Ok(PyBytes::new_bound(py, &compressed)) } + #[pyo3(signature = (flush_mode=None))] fn flush<'p>( &mut self, py: Python<'p>, diff --git a/rust-ext/src/compressor_multi.rs b/rust-ext/src/compressor_multi.rs index 3d85ed1f..0a973d50 100644 --- a/rust-ext/src/compressor_multi.rs +++ b/rust-ext/src/compressor_multi.rs @@ -68,7 +68,7 @@ pub fn multi_compress_to_buffer( total_source_size += slice.len(); } } - } else if let Ok(list) = data.extract::<&PyList>() { + } else if let Ok(list) = data.extract::>() { sources.reserve_exact(list.len()); for (i, item) in list.iter().enumerate() { diff --git a/rust-ext/src/decompressionobj.rs b/rust-ext/src/decompressionobj.rs index 8922a0ce..6c256c6f 100644 --- a/rust-ext/src/decompressionobj.rs +++ b/rust-ext/src/decompressionobj.rs @@ -102,6 +102,7 @@ impl ZstdDecompressionObj { empty.call_method1("join", (chunks,)) } + #[pyo3(signature = (length=None))] #[allow(unused_variables)] fn flush<'p>(&self, py: Python<'p>, length: Option) -> PyResult> { Ok(PyBytes::new_bound(py, &[])) diff --git a/rust-ext/src/decompressor_multi.rs b/rust-ext/src/decompressor_multi.rs index 1e37202c..4bf1ecc2 100644 --- a/rust-ext/src/decompressor_multi.rs +++ b/rust-ext/src/decompressor_multi.rs @@ -99,7 +99,7 @@ pub fn multi_decompress_to_buffer( offset += 1; } } - } else if let Ok(list) = frames.extract::<&PyList>() { + } else if let Ok(list) = frames.extract::>() { if decompressed_sizes.is_some() && frame_sizes.len() != list.len() { return Err(PyValueError::new_err(format!( "decompressed_sizes size mismatch; expected {}; got {}", From 29ca1290da808b2580d656f8e1cbd6d3df04447f Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Sat, 22 Feb 2025 15:35:48 -0700 Subject: [PATCH 2/2] update CI config to test rust on 3.13 --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73de905d..1df7bcb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,9 +77,8 @@ jobs: run: | python -m pip install --require-hashes -r ci/requirements.txt - # TODO enable once PyO3 supports 3.13. - name: Build (Rust) - if: matrix.arch == 'x64' && matrix.py != '3.13' + if: matrix.arch == 'x64' env: PIP_CONSTRAINT: 'ci/constraints.txt' run: |