Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 86 additions & 24 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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-*/*
args: --non-interactive --skip-existing wheels-*/*
6 changes: 3 additions & 3 deletions poppy/src/bin/poppy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,15 @@ 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);
}
}

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) {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions poppy/src/bloom/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
Expand All @@ -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(),
Expand Down
7 changes: 3 additions & 4 deletions poppy/src/bloom/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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}",
);
}
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ doc = false

[dependencies]
poppy = { path = "../poppy", package = "poppy-filters" }
pyo3 = "0.20.0"
pyo3 = "0.25.1"
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin==1.6.0,<2.0"]
requires = ["maturin==1.9.1,<2.0"]
build-backend = "maturin"

[project]
Expand Down
12 changes: 5 additions & 7 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<Vec<u8>> {
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::<Vec<u8>>().as_slice());
Ok(b)
Ok(cursor.bytes().flatten().collect::<Vec<u8>>())
}

/// Save filter into a file
Expand Down Expand Up @@ -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::<BloomFilter>()?;
m.add_function(wrap_pyfunction!(load, m)?)?;
m.add_function(wrap_pyfunction!(loads, m)?)?;
Expand Down
Loading