From 54704490df0caaa4d92a96fa80f8d747ffce01f2 Mon Sep 17 00:00:00 2001 From: Paul Sanders Date: Mon, 18 Nov 2024 14:33:28 -0500 Subject: [PATCH] Update for pyo3 0.23 --- Cargo.lock | 30 +++++++++++++++--------------- Cargo.toml | 4 ++-- src/lib.rs | 29 ++++++++++++++--------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e474996..507444a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,16 +185,16 @@ dependencies = [ [[package]] name = "prelude-xml-parser" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d33899e54fb78839fc46e1f9349f2bac40b168c87d8ff2220eda906d9114ea" +checksum = "d339af820967c38918e82593dc2640606f1cc0434b0fa453dfdbbd1e51885579" dependencies = [ "chrono", "pyo3", "serde", "serde-xml-rs", "serde_json", - "thiserror 1.0.68", + "thiserror 2.0.3", ] [[package]] @@ -208,9 +208,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884" +checksum = "7ebb0c0cc0de9678e53be9ccf8a2ab53045e6e3a8be03393ceccc5e7396ccb40" dependencies = [ "cfg-if", "indoc", @@ -226,9 +226,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38" +checksum = "80e3ce69c4ec34476534b490e412b871ba03a82e35604c3dfb95fcb6bfb60c09" dependencies = [ "once_cell", "target-lexicon", @@ -236,9 +236,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636" +checksum = "3b09f311c76b36dfd6dd6f7fa6f9f18e7e46a1c937110d283e80b12ba2468a75" dependencies = [ "libc", "pyo3-build-config", @@ -246,9 +246,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453" +checksum = "fd4f74086536d1e1deaff99ec0387481fb3325c82e4e48be0e75ab3d3fcb487a" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -258,9 +258,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe" +checksum = "9e77dfeb76b32bbf069144a5ea0a36176ab59c8db9ce28732d0f06f096bbfbc8" dependencies = [ "heck", "proc-macro2", @@ -324,9 +324,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 4e18b47..7d680b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.93" chrono = "0.4.38" -prelude-xml-parser = { version = "0.7.2", features = ["python"] } -pyo3 = { version = "0.22.6", features = ["extension-module"] } +prelude-xml-parser = { version = "0.7.3", features = ["python"] } +pyo3 = { version = "0.23.0", features = ["extension-module"] } roxmltree = "0.20.0" serde = { version = "1.0.215", features = ["derive"] } serde-xml-rs = "0.6.0" diff --git a/src/lib.rs b/src/lib.rs index 7316603..acdd70d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ fn py_list_append<'py>( value: Option<&str>, list: &'py Bound<'py, PyList>, ) -> PyResult<&'py Bound<'py, PyList>> { - let datetime = py.import_bound("datetime")?; + let datetime = py.import("datetime")?; let date = datetime.getattr("date")?; match value { @@ -79,7 +79,7 @@ fn add_item<'py>( value: Option<&str>, form_data: &'py Bound<'py, PyDict>, ) -> PyResult<&'py Bound<'py, PyDict>> { - let datetime = py.import_bound("datetime")?; + let datetime = py.import("datetime")?; let date = datetime.getattr("date")?; match value { @@ -122,7 +122,7 @@ fn parse_xml<'py>( }; if !form_name.is_empty() { if let Some(d) = data.get_mut(&form_name) { - let form_data = PyDict::new_bound(py); + let form_data = PyDict::new(py); for child in form.children() { if child.is_element() && child.tag_name().name() != "" { let key = if short_names { @@ -136,7 +136,7 @@ fn parse_xml<'py>( d.push(form_data); } else { let mut items: Vec> = Vec::new(); - let form_data = PyDict::new_bound(py); + let form_data = PyDict::new(py); for child in form.children() { if child.is_element() && child.tag_name().name() != "" { let key = if short_names { @@ -147,12 +147,13 @@ fn parse_xml<'py>( add_item(py, &key, child.text(), &form_data)?; } } - items.push(form_data.into_py_dict_bound(py)); + items.push(form_data.into_py_dict(py)?); data.insert(form_name, items); } } } - return Ok(data.into_py_dict_bound(py)); + let data_dict = data.into_py_dict(py)?; + Ok(data_dict) } Err(e) => Err(ParsingError::new_err(format!( "Error parsing xml file: {:?}", @@ -176,7 +177,7 @@ fn parse_xml_pandas<'py>( match reader { Ok(r) => match Document::parse(&r) { Ok(doc) => { - let data = PyDict::new_bound(py); + let data = PyDict::new(py); let tree = doc.root_element(); for form in tree.children() { @@ -191,14 +192,15 @@ fn parse_xml_pandas<'py>( py_list_append(py, child.text(), &c.extract()?)?; data.set_item(column, c)?; } else { - let list = PyList::empty_bound(py); + let list = PyList::empty(py); py_list_append(py, child.text(), &list)?; data.set_item(column, list)?; } } } } - return Ok(data.into_py_dict_bound(py)); + let data_dict = data.into_py_dict(py)?; + Ok(data_dict) } Err(e) => Err(ParsingError::new_err(format!( "Error parsing xml file: {:?}", @@ -314,15 +316,12 @@ fn _prelude_parser(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(parse_subject_native_string, m)?)?; m.add_function(wrap_pyfunction!(parse_user_native_file, m)?)?; m.add_function(wrap_pyfunction!(parse_user_native_string, m)?)?; - m.add( - "FileNotFoundError", - py.get_type_bound::(), - )?; + m.add("FileNotFoundError", py.get_type::())?; m.add( "InvalidFileTypeError", - py.get_type_bound::(), + py.get_type::(), )?; - m.add("ParsingError", py.get_type_bound::())?; + m.add("ParsingError", py.get_type::())?; Ok(()) }