From dd23de9d4de745933832f68e17cca9e30a1c0321 Mon Sep 17 00:00:00 2001 From: qjerome Date: Tue, 15 Jul 2025 11:12:23 +0200 Subject: [PATCH 1/4] chore: upgrade pyo3 --- python/Cargo.toml | 2 +- python/src/lib.rs | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/python/Cargo.toml b/python/Cargo.toml index 85ee573..934f2cd 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -19,4 +19,4 @@ doc = false [dependencies] poppy = { path = "../poppy", package = "poppy-filters" } -pyo3 = "0.20.0" +pyo3 = "0.25.1" diff --git a/python/src/lib.rs b/python/src/lib.rs index 469722a..c577495 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -5,7 +5,7 @@ use std::{ }; use poppy::Params; -use pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes}; +use pyo3::{exceptions::PyValueError, prelude::*}; #[pyclass] pub struct BloomFilter(poppy::BloomFilter); @@ -110,12 +110,11 @@ impl BloomFilter { } /// Dumps bloom filter into a binary form - pub fn dumps<'py>(&self, py: Python<'py>) -> PyResult<&'py PyBytes> { + pub fn dumps(&self) -> PyResult> { let mut cursor = io::Cursor::new(vec![]); self.0.write(&mut cursor).map_err(Error::from)?; cursor.set_position(0); - let b = PyBytes::new(py, cursor.bytes().flatten().collect::>().as_slice()); - Ok(b) + Ok(cursor.bytes().flatten().collect::>()) } /// Save filter into a file @@ -153,9 +152,8 @@ impl BloomFilter { } /// Python bindings to Poppy bloom filter library (written in Rust) -#[pymodule] -#[pyo3(name = "poppy")] -fn poppy_py(_py: Python, m: &PyModule) -> PyResult<()> { +#[pymodule(name = "poppy")] +fn poppy_py(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_function(wrap_pyfunction!(load, m)?)?; m.add_function(wrap_pyfunction!(loads, m)?)?; From 6082dd1ca811d0ab7d2ad8173f9545eadc37070a Mon Sep 17 00:00:00 2001 From: qjerome Date: Tue, 15 Jul 2025 11:20:51 +0200 Subject: [PATCH 2/4] =?UTF-8?q?chore:=C2=A0upgrade=20maturin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 4577772..d213ca1 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin==1.6.0,<2.0"] +requires = ["maturin==1.9.1,<2.0"] build-backend = "maturin" [project] From 02ad0045496027ab05de601be37e1f2f8a1cb118 Mon Sep 17 00:00:00 2001 From: qjerome Date: Tue, 15 Jul 2025 11:25:12 +0200 Subject: [PATCH 3/4] chore: clippy lints --- poppy/src/bin/poppy.rs | 6 +++--- poppy/src/bloom/v1.rs | 8 ++++---- poppy/src/bloom/v2.rs | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/poppy/src/bin/poppy.rs b/poppy/src/bin/poppy.rs index b3c0412..814a00c 100644 --- a/poppy/src/bin/poppy.rs +++ b/poppy/src/bin/poppy.rs @@ -429,7 +429,7 @@ fn main() -> Result<(), anyhow::Error> { } if !marked.contains(&h) { - dataset_size += line.as_bytes().len(); + dataset_size += line.len(); marked.insert(h); entries.push(line); } @@ -437,7 +437,7 @@ fn main() -> Result<(), anyhow::Error> { let b = match o.file { Some(f) => { - println!("Benchmarking filter: {}", f); + println!("Benchmarking filter: {f}"); let b = BloomFilter::from_reader(File::open(&f)?)?; for entry in &entries { if !b.contains_bytes(entry) { @@ -528,7 +528,7 @@ fn main() -> Result<(), anyhow::Error> { "\tcondition: {}% of queried values are in filter", 100 - mut_prob ); - println!("\tquery duration: {:?}", query_dur); + println!("\tquery duration: {query_dur:?}"); println!( "\tquery speed: {:.1} queries/s -> {:.1} MB/s", qps, diff --git a/poppy/src/bloom/v1.rs b/poppy/src/bloom/v1.rs index 146b93a..39ed643 100644 --- a/poppy/src/bloom/v1.rs +++ b/poppy/src/bloom/v1.rs @@ -650,7 +650,7 @@ mod test { let reader = io::BufReader::new(f); for line in reader.lines() { let line = line.unwrap(); - let size = line.as_bytes().len(); + let size = line.len(); if lines.insert(line) { dataset_size += size } @@ -678,8 +678,8 @@ mod test { ); let bit_size = utils::bit_size(count, fp_rate); - eprintln!("count: {}", count); - eprintln!("proba: {}", fp_rate); + eprintln!("count: {count}"); + eprintln!("proba: {fp_rate}"); eprintln!( "bit_size:{} optimized: {} expected_proba: {}", ByteSize::from_bits(bit_size as usize), @@ -693,7 +693,7 @@ mod test { ); eprintln!("\nInsertion performance:"); - eprintln!("\tinsert duration: {:?}", insert_dur); + eprintln!("\tinsert duration: {insert_dur:?}"); eprintln!( "\tinsertion speed: {:.1} entries/s -> {:.1} MB/s", count as f64 / insert_dur.as_secs_f64(), diff --git a/poppy/src/bloom/v2.rs b/poppy/src/bloom/v2.rs index 39fc238..35db3da 100644 --- a/poppy/src/bloom/v2.rs +++ b/poppy/src/bloom/v2.rs @@ -395,6 +395,7 @@ impl BloomFilter { if !bucket.set_nth_bit(ibit as usize) { new = true } + debug_assert!(bucket.get_nth_bit(ibit as usize)); } @@ -905,9 +906,7 @@ mod test { if !avg_fpp.is_nan() { assert!( avg_fpp < (fpp * (1.0 + tol)), - "real fpp: {} VS expected: {}", - avg_fpp, - fpp, + "real fpp: {avg_fpp} VS expected: {fpp}", ); } } @@ -1075,7 +1074,7 @@ mod test { let reader = io::BufReader::new(f); for line in reader.lines() { let line = line.unwrap(); - let size = line.as_bytes().len(); + let size = line.len(); if lines.insert(line) { dataset_size += size } From 6e19f393260ed548d7cdfde7a20534115372ac0d Mon Sep 17 00:00:00 2001 From: qjerome Date: Tue, 15 Jul 2025 11:40:26 +0200 Subject: [PATCH 4/4] chore(workflow): update python workflow --- .github/workflows/python.yml | 110 +++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 24 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 9be297e..cc3b0ab 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -# This file is autogenerated by maturin v1.5.0 +# This file is autogenerated by maturin v1.9.1 # To update, run # # maturin generate-ci github @@ -20,71 +20,122 @@ permissions: jobs: linux: - runs-on: ubuntu-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] + platform: + - runner: ubuntu-22.04 + target: x86_64 + - runner: ubuntu-22.04 + target: x86 + - runner: ubuntu-22.04 + target: aarch64 + - runner: ubuntu-22.04 + target: armv7 + - runner: ubuntu-22.04 + target: s390x + - runner: ubuntu-22.04 + target: ppc64le steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: 3.x - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter -m python/Cargo.toml - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} manylinux: auto - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels-linux-${{ matrix.target }} + name: wheels-linux-${{ matrix.platform.target }} + path: dist + + musllinux: + runs-on: ${{ matrix.platform.runner }} + strategy: + matrix: + platform: + - runner: ubuntu-22.04 + target: x86_64 + - runner: ubuntu-22.04 + target: x86 + - runner: ubuntu-22.04 + target: aarch64 + - runner: ubuntu-22.04 + target: armv7 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.platform.target }} + args: --release --out dist --find-interpreter -m python/Cargo.toml + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} + manylinux: musllinux_1_2 + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-musllinux-${{ matrix.platform.target }} path: dist windows: - runs-on: windows-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x64, x86] + platform: + - runner: windows-latest + target: x64 + - runner: windows-latest + target: x86 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.8' - architecture: ${{ matrix.target }} + python-version: 3.x + architecture: ${{ matrix.platform.target }} - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter -m python/Cargo.toml - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels-windows-${{ matrix.target }} + name: wheels-windows-${{ matrix.platform.target }} path: dist macos: - runs-on: macos-latest + runs-on: ${{ matrix.platform.runner }} strategy: matrix: - target: [x86_64, aarch64] + platform: + - runner: macos-13 + target: x86_64 + - runner: macos-14 + target: aarch64 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: 3.x - name: Build wheels uses: PyO3/maturin-action@v1 with: - target: ${{ matrix.target }} + target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter -m python/Cargo.toml - sccache: 'true' + sccache: ${{ !startsWith(github.ref, 'refs/tags/') }} - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels-macos-${{ matrix.target }} + name: wheels-macos-${{ matrix.platform.target }} path: dist sdist: @@ -105,15 +156,26 @@ jobs: release: name: Release runs-on: ubuntu-latest - if: "startsWith(github.ref, 'refs/tags/')" - needs: [linux, windows, macos, sdist] + if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} + needs: [linux, musllinux, windows, macos, sdist] permissions: + # Use to sign the release artifacts id-token: write - environment: release + # Used to upload release artifacts + contents: write + # Used to generate artifact attestation + attestations: write steps: - uses: actions/download-artifact@v4 + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v2 + with: + subject-path: 'wheels-*/*' - name: Publish to PyPI + if: ${{ startsWith(github.ref, 'refs/tags/') }} uses: PyO3/maturin-action@v1 + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file + args: --non-interactive --skip-existing wheels-*/*