Skip to content

Commit 4a03e84

Browse files
authored
chore: upgrade pyo3 (#17)
* chore: upgrade pyo3 * chore: upgrade maturin * chore: clippy lints * chore(workflow): update python workflow
1 parent b814bb9 commit 4a03e84

File tree

7 files changed

+103
-44
lines changed

7 files changed

+103
-44
lines changed

.github/workflows/python.yml

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file is autogenerated by maturin v1.5.0
1+
# This file is autogenerated by maturin v1.9.1
22
# To update, run
33
#
44
# maturin generate-ci github
@@ -20,71 +20,122 @@ permissions:
2020

2121
jobs:
2222
linux:
23-
runs-on: ubuntu-latest
23+
runs-on: ${{ matrix.platform.runner }}
2424
strategy:
2525
matrix:
26-
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
26+
platform:
27+
- runner: ubuntu-22.04
28+
target: x86_64
29+
- runner: ubuntu-22.04
30+
target: x86
31+
- runner: ubuntu-22.04
32+
target: aarch64
33+
- runner: ubuntu-22.04
34+
target: armv7
35+
- runner: ubuntu-22.04
36+
target: s390x
37+
- runner: ubuntu-22.04
38+
target: ppc64le
2739
steps:
2840
- uses: actions/checkout@v4
2941
- uses: actions/setup-python@v5
3042
with:
31-
python-version: '3.8'
43+
python-version: 3.x
3244
- name: Build wheels
3345
uses: PyO3/maturin-action@v1
3446
with:
35-
target: ${{ matrix.target }}
47+
target: ${{ matrix.platform.target }}
3648
args: --release --out dist --find-interpreter -m python/Cargo.toml
37-
sccache: 'true'
49+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
3850
manylinux: auto
3951
- name: Upload wheels
4052
uses: actions/upload-artifact@v4
4153
with:
42-
name: wheels-linux-${{ matrix.target }}
54+
name: wheels-linux-${{ matrix.platform.target }}
55+
path: dist
56+
57+
musllinux:
58+
runs-on: ${{ matrix.platform.runner }}
59+
strategy:
60+
matrix:
61+
platform:
62+
- runner: ubuntu-22.04
63+
target: x86_64
64+
- runner: ubuntu-22.04
65+
target: x86
66+
- runner: ubuntu-22.04
67+
target: aarch64
68+
- runner: ubuntu-22.04
69+
target: armv7
70+
steps:
71+
- uses: actions/checkout@v4
72+
- uses: actions/setup-python@v5
73+
with:
74+
python-version: 3.x
75+
- name: Build wheels
76+
uses: PyO3/maturin-action@v1
77+
with:
78+
target: ${{ matrix.platform.target }}
79+
args: --release --out dist --find-interpreter -m python/Cargo.toml
80+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
81+
manylinux: musllinux_1_2
82+
- name: Upload wheels
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: wheels-musllinux-${{ matrix.platform.target }}
4386
path: dist
4487

4588
windows:
46-
runs-on: windows-latest
89+
runs-on: ${{ matrix.platform.runner }}
4790
strategy:
4891
matrix:
49-
target: [x64, x86]
92+
platform:
93+
- runner: windows-latest
94+
target: x64
95+
- runner: windows-latest
96+
target: x86
5097
steps:
5198
- uses: actions/checkout@v4
5299
- uses: actions/setup-python@v5
53100
with:
54-
python-version: '3.8'
55-
architecture: ${{ matrix.target }}
101+
python-version: 3.x
102+
architecture: ${{ matrix.platform.target }}
56103
- name: Build wheels
57104
uses: PyO3/maturin-action@v1
58105
with:
59-
target: ${{ matrix.target }}
106+
target: ${{ matrix.platform.target }}
60107
args: --release --out dist --find-interpreter -m python/Cargo.toml
61-
sccache: 'true'
108+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
62109
- name: Upload wheels
63110
uses: actions/upload-artifact@v4
64111
with:
65-
name: wheels-windows-${{ matrix.target }}
112+
name: wheels-windows-${{ matrix.platform.target }}
66113
path: dist
67114

68115
macos:
69-
runs-on: macos-latest
116+
runs-on: ${{ matrix.platform.runner }}
70117
strategy:
71118
matrix:
72-
target: [x86_64, aarch64]
119+
platform:
120+
- runner: macos-13
121+
target: x86_64
122+
- runner: macos-14
123+
target: aarch64
73124
steps:
74125
- uses: actions/checkout@v4
75126
- uses: actions/setup-python@v5
76127
with:
77-
python-version: '3.8'
128+
python-version: 3.x
78129
- name: Build wheels
79130
uses: PyO3/maturin-action@v1
80131
with:
81-
target: ${{ matrix.target }}
132+
target: ${{ matrix.platform.target }}
82133
args: --release --out dist --find-interpreter -m python/Cargo.toml
83-
sccache: 'true'
134+
sccache: ${{ !startsWith(github.ref, 'refs/tags/') }}
84135
- name: Upload wheels
85136
uses: actions/upload-artifact@v4
86137
with:
87-
name: wheels-macos-${{ matrix.target }}
138+
name: wheels-macos-${{ matrix.platform.target }}
88139
path: dist
89140

90141
sdist:
@@ -105,15 +156,26 @@ jobs:
105156
release:
106157
name: Release
107158
runs-on: ubuntu-latest
108-
if: "startsWith(github.ref, 'refs/tags/')"
109-
needs: [linux, windows, macos, sdist]
159+
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
160+
needs: [linux, musllinux, windows, macos, sdist]
110161
permissions:
162+
# Use to sign the release artifacts
111163
id-token: write
112-
environment: release
164+
# Used to upload release artifacts
165+
contents: write
166+
# Used to generate artifact attestation
167+
attestations: write
113168
steps:
114169
- uses: actions/download-artifact@v4
170+
- name: Generate artifact attestation
171+
uses: actions/attest-build-provenance@v2
172+
with:
173+
subject-path: 'wheels-*/*'
115174
- name: Publish to PyPI
175+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
116176
uses: PyO3/maturin-action@v1
177+
env:
178+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
117179
with:
118180
command: upload
119-
args: --non-interactive --skip-existing wheels-*/*
181+
args: --non-interactive --skip-existing wheels-*/*

poppy/src/bin/poppy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ fn main() -> Result<(), anyhow::Error> {
429429
}
430430

431431
if !marked.contains(&h) {
432-
dataset_size += line.as_bytes().len();
432+
dataset_size += line.len();
433433
marked.insert(h);
434434
entries.push(line);
435435
}
436436
}
437437

438438
let b = match o.file {
439439
Some(f) => {
440-
println!("Benchmarking filter: {}", f);
440+
println!("Benchmarking filter: {f}");
441441
let b = BloomFilter::from_reader(File::open(&f)?)?;
442442
for entry in &entries {
443443
if !b.contains_bytes(entry) {
@@ -528,7 +528,7 @@ fn main() -> Result<(), anyhow::Error> {
528528
"\tcondition: {}% of queried values are in filter",
529529
100 - mut_prob
530530
);
531-
println!("\tquery duration: {:?}", query_dur);
531+
println!("\tquery duration: {query_dur:?}");
532532
println!(
533533
"\tquery speed: {:.1} queries/s -> {:.1} MB/s",
534534
qps,

poppy/src/bloom/v1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ mod test {
650650
let reader = io::BufReader::new(f);
651651
for line in reader.lines() {
652652
let line = line.unwrap();
653-
let size = line.as_bytes().len();
653+
let size = line.len();
654654
if lines.insert(line) {
655655
dataset_size += size
656656
}
@@ -678,8 +678,8 @@ mod test {
678678
);
679679

680680
let bit_size = utils::bit_size(count, fp_rate);
681-
eprintln!("count: {}", count);
682-
eprintln!("proba: {}", fp_rate);
681+
eprintln!("count: {count}");
682+
eprintln!("proba: {fp_rate}");
683683
eprintln!(
684684
"bit_size:{} optimized: {} expected_proba: {}",
685685
ByteSize::from_bits(bit_size as usize),
@@ -693,7 +693,7 @@ mod test {
693693
);
694694

695695
eprintln!("\nInsertion performance:");
696-
eprintln!("\tinsert duration: {:?}", insert_dur);
696+
eprintln!("\tinsert duration: {insert_dur:?}");
697697
eprintln!(
698698
"\tinsertion speed: {:.1} entries/s -> {:.1} MB/s",
699699
count as f64 / insert_dur.as_secs_f64(),

poppy/src/bloom/v2.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ impl BloomFilter {
395395
if !bucket.set_nth_bit(ibit as usize) {
396396
new = true
397397
}
398+
398399
debug_assert!(bucket.get_nth_bit(ibit as usize));
399400
}
400401

@@ -905,9 +906,7 @@ mod test {
905906
if !avg_fpp.is_nan() {
906907
assert!(
907908
avg_fpp < (fpp * (1.0 + tol)),
908-
"real fpp: {} VS expected: {}",
909-
avg_fpp,
910-
fpp,
909+
"real fpp: {avg_fpp} VS expected: {fpp}",
911910
);
912911
}
913912
}
@@ -1075,7 +1074,7 @@ mod test {
10751074
let reader = io::BufReader::new(f);
10761075
for line in reader.lines() {
10771076
let line = line.unwrap();
1078-
let size = line.as_bytes().len();
1077+
let size = line.len();
10791078
if lines.insert(line) {
10801079
dataset_size += size
10811080
}

python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ doc = false
1919

2020
[dependencies]
2121
poppy = { path = "../poppy", package = "poppy-filters" }
22-
pyo3 = "0.20.0"
22+
pyo3 = "0.25.1"

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["maturin==1.6.0,<2.0"]
2+
requires = ["maturin==1.9.1,<2.0"]
33
build-backend = "maturin"
44

55
[project]

python/src/lib.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
};
66

77
use poppy::Params;
8-
use pyo3::{exceptions::PyValueError, prelude::*, types::PyBytes};
8+
use pyo3::{exceptions::PyValueError, prelude::*};
99

1010
#[pyclass]
1111
pub struct BloomFilter(poppy::BloomFilter);
@@ -110,12 +110,11 @@ impl BloomFilter {
110110
}
111111

112112
/// Dumps bloom filter into a binary form
113-
pub fn dumps<'py>(&self, py: Python<'py>) -> PyResult<&'py PyBytes> {
113+
pub fn dumps(&self) -> PyResult<Vec<u8>> {
114114
let mut cursor = io::Cursor::new(vec![]);
115115
self.0.write(&mut cursor).map_err(Error::from)?;
116116
cursor.set_position(0);
117-
let b = PyBytes::new(py, cursor.bytes().flatten().collect::<Vec<u8>>().as_slice());
118-
Ok(b)
117+
Ok(cursor.bytes().flatten().collect::<Vec<u8>>())
119118
}
120119

121120
/// Save filter into a file
@@ -153,9 +152,8 @@ impl BloomFilter {
153152
}
154153

155154
/// Python bindings to Poppy bloom filter library (written in Rust)
156-
#[pymodule]
157-
#[pyo3(name = "poppy")]
158-
fn poppy_py(_py: Python, m: &PyModule) -> PyResult<()> {
155+
#[pymodule(name = "poppy")]
156+
fn poppy_py(m: &Bound<'_, PyModule>) -> PyResult<()> {
159157
m.add_class::<BloomFilter>()?;
160158
m.add_function(wrap_pyfunction!(load, m)?)?;
161159
m.add_function(wrap_pyfunction!(loads, m)?)?;

0 commit comments

Comments
 (0)