Skip to content

Commit 05fefd2

Browse files
authored
Merge branch '6.x' into drop-python-3.7-3.9
2 parents 691d28c + 5d8f7f4 commit 05fefd2

File tree

8 files changed

+151
-88
lines changed

8 files changed

+151
-88
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
name = "neo4j-rust-ext"
33
version = "0.1.0"
44
edition = "2021"
5+
rust-version = "1.77"
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78
[lib]
89
name = "neo4j_rust_ext"
910
crate-type = ["cdylib"]
1011

1112
[dependencies]
12-
pyo3 = "0.22.4"
13+
pyo3 = "0.24.2"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For that, simply make sure you haven't installed `neo4j-rust-ext` but *only* `ne
3131
For many operating systems and architectures, the pre-built wheels will work out of the box.
3232
If they don't, pip (or any other Python packaging front-end) will try to build the extension from source.
3333
Here's what you'll need for this:
34-
* Rust 1.67.0 or later:
34+
* Rust 1.77 or later:
3535
https://www.rust-lang.org/tools/install
3636
* Further build tools (depending on the platform).
3737
E.g., `gcc` on Ubuntu: `sudo apt install gcc`

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ authors = [
2222
{name = "Neo4j, Inc.", email = "drivers@neo4j.com"},
2323
]
2424
dependencies = [
25-
"neo4j == 5.28.0"
25+
"neo4j == 5.28.1"
2626
]
2727
requires-python = ">=3.10"
2828
keywords = ["neo4j", "graph", "database"]
@@ -39,7 +39,7 @@ classifiers = [
3939
"Topic :: Database",
4040
"Topic :: Software Development",
4141
]
42-
version = "5.28.0.0"
42+
version = "5.28.1.0"
4343

4444
[project.urls]
4545
Homepage = "https://neo4j.com/"
@@ -55,7 +55,7 @@ pandas = ["neo4j[pandas]"]
5555
pyarrow = ["neo4j[pyarrow]"]
5656

5757
[build-system]
58-
requires = ["maturin ~= 1.6.0"]
58+
requires = ["maturin ~= 1.8.3"]
5959
build-backend = "maturin"
6060

6161
[tool.maturin]

src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ use pyo3::basic::CompareOp;
1919
use pyo3::exceptions::PyValueError;
2020
use pyo3::prelude::*;
2121
use pyo3::types::{PyBytes, PyTuple};
22+
use pyo3::IntoPyObjectExt;
2223

23-
/// A Python module implemented in Rust.
24-
#[pymodule]
24+
#[pymodule(gil_used = false)]
2525
#[pyo3(name = "_rust")]
2626
fn packstream(m: &Bound<PyModule>) -> PyResult<()> {
2727
let py = m.py();
2828

2929
m.add_class::<Structure>()?;
3030

31-
let mod_v1 = PyModule::new_bound(py, "v1")?;
31+
let mod_v1 = PyModule::new(py, "v1")?;
32+
mod_v1.gil_used(false)?;
3233
v1::register(&mod_v1)?;
3334
m.add_submodule(&mod_v1)?;
3435
register_package(&mod_v1, "v1")?;
@@ -40,9 +41,9 @@ fn packstream(m: &Bound<PyModule>) -> PyResult<()> {
4041
// https://github.com/PyO3/pyo3/issues/1517#issuecomment-808664021
4142
fn register_package(m: &Bound<PyModule>, name: &str) -> PyResult<()> {
4243
let py = m.py();
43-
let module_name = format!("neo4j._codec.packstream._rust.{name}").into_py(py);
44+
let module_name = format!("neo4j._codec.packstream._rust.{name}").into_pyobject(py)?;
4445

45-
py.import_bound("sys")?
46+
py.import("sys")?
4647
.getattr("modules")?
4748
.set_item(&module_name, m)?;
4849
m.setattr("__name__", &module_name)?;
@@ -73,12 +74,12 @@ impl Structure {
7374

7475
#[getter(tag)]
7576
fn read_tag<'py>(&self, py: Python<'py>) -> Bound<'py, PyBytes> {
76-
PyBytes::new_bound(py, &[self.tag])
77+
PyBytes::new(py, &[self.tag])
7778
}
7879

7980
#[getter(fields)]
80-
fn read_fields<'py>(&self, py: Python<'py>) -> Bound<'py, PyTuple> {
81-
PyTuple::new_bound(py, &self.fields)
81+
fn read_fields<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyTuple>> {
82+
PyTuple::new(py, &self.fields)
8283
}
8384

8485
fn eq(&self, other: &Self, py: Python<'_>) -> PyResult<bool> {
@@ -100,8 +101,8 @@ impl Structure {
100101

101102
fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> PyResult<PyObject> {
102103
Ok(match op {
103-
CompareOp::Eq => self.eq(other, py)?.into_py(py),
104-
CompareOp::Ne => (!self.eq(other, py)?).into_py(py),
104+
CompareOp::Eq => self.eq(other, py)?.into_py_any(py)?,
105+
CompareOp::Ne => (!self.eq(other, py)?).into_py_any(py)?,
105106
_ => py.NotImplemented(),
106107
})
107108
}

src/v1/pack.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use std::borrow::Cow;
1717
use std::sync::atomic::{AtomicBool, Ordering};
1818

1919
use pyo3::exceptions::{PyImportError, PyOverflowError, PyTypeError, PyValueError};
20-
use pyo3::intern;
2120
use pyo3::prelude::*;
2221
use pyo3::sync::GILOnceCell;
2322
use pyo3::types::{PyBytes, PyDict, PyString, PyType};
23+
use pyo3::{intern, IntoPyObjectExt};
2424

2525
use super::{
2626
BYTES_16, BYTES_32, BYTES_8, FALSE, FLOAT_64, INT_16, INT_32, INT_64, INT_8, LIST_16, LIST_32,
@@ -68,31 +68,31 @@ impl TypeMappings {
6868
.ok_or_else(|| {
6969
PyErr::new::<PyValueError, _>("Type mappings are missing INT_TYPES.")
7070
})?
71-
.into_py(py),
71+
.into_py_any(py)?,
7272
float_types: locals
7373
.get_item("FLOAT_TYPES")?
7474
.ok_or_else(|| {
7575
PyErr::new::<PyValueError, _>("Type mappings are missing FLOAT_TYPES.")
7676
})?
77-
.into_py(py),
77+
.into_py_any(py)?,
7878
sequence_types: locals
7979
.get_item("SEQUENCE_TYPES")?
8080
.ok_or_else(|| {
8181
PyErr::new::<PyValueError, _>("Type mappings are missing SEQUENCE_TYPES.")
8282
})?
83-
.into_py(py),
83+
.into_py_any(py)?,
8484
mapping_types: locals
8585
.get_item("MAPPING_TYPES")?
8686
.ok_or_else(|| {
8787
PyErr::new::<PyValueError, _>("Type mappings are missing MAPPING_TYPES.")
8888
})?
89-
.into_py(py),
89+
.into_py_any(py)?,
9090
bytes_types: locals
9191
.get_item("BYTES_TYPES")?
9292
.ok_or_else(|| {
9393
PyErr::new::<PyValueError, _>("Type mappings are missing BYTES_TYPES.")
9494
})?
95-
.into_py(py),
95+
.into_py_any(py)?,
9696
})
9797
}
9898
}
@@ -103,9 +103,9 @@ static TYPE_MAPPINGS_INIT: AtomicBool = AtomicBool::new(false);
103103
fn get_type_mappings(py: Python<'_>) -> PyResult<&'static TypeMappings> {
104104
let mappings = TYPE_MAPPINGS.get_or_try_init(py, || {
105105
fn init(py: Python<'_>) -> PyResult<TypeMappings> {
106-
let locals = PyDict::new_bound(py);
107-
py.run_bound(
108-
"from neo4j._codec.packstream.v1.types import *",
106+
let locals = PyDict::new(py);
107+
py.run(
108+
c"from neo4j._codec.packstream.v1.types import *",
109109
None,
110110
Some(&locals),
111111
)?;
@@ -132,7 +132,7 @@ pub(super) fn pack<'py>(
132132
let type_mappings = get_type_mappings(py)?;
133133
let mut encoder = PackStreamEncoder::new(dehydration_hooks, type_mappings);
134134
encoder.write(value)?;
135-
Ok(PyBytes::new_bound(py, &encoder.buffer))
135+
Ok(PyBytes::new(py, &encoder.buffer))
136136
}
137137

138138
struct PackStreamEncoder<'a> {
@@ -176,7 +176,7 @@ impl<'a> PackStreamEncoder<'a> {
176176
return self.write_int(value);
177177
}
178178

179-
if value.is_instance(&PyType::new_bound::<PyString>(py))? {
179+
if value.is_instance(&PyType::new::<PyString>(py))? {
180180
return self.write_string(value.extract::<&str>()?);
181181
}
182182

@@ -187,14 +187,14 @@ impl<'a> PackStreamEncoder<'a> {
187187
if value.is_instance(self.type_mappings.sequence_types.bind(py))? {
188188
let size = Self::usize_to_u64(value.len()?)?;
189189
self.write_list_header(size)?;
190-
return value.iter()?.try_for_each(|item| self.write(&item?));
190+
return value.try_iter()?.try_for_each(|item| self.write(&item?));
191191
}
192192

193193
if value.is_instance(self.type_mappings.mapping_types.bind(py))? {
194194
let size = Self::usize_to_u64(value.getattr(intern!(py, "keys"))?.call0()?.len()?)?;
195195
self.write_dict_header(size)?;
196196
let items = value.getattr(intern!(py, "items"))?.call0()?;
197-
return items.iter()?.try_for_each(|item| {
197+
return items.try_iter()?.try_for_each(|item| {
198198
let (key, value) = item?.extract::<(Bound<PyAny>, Bound<PyAny>)>()?;
199199
let key = match key.extract::<&str>() {
200200
Ok(key) => key,

0 commit comments

Comments
 (0)