From 4a5407136d30ebcb8ab8f02be5cf50c0afa31fe9 Mon Sep 17 00:00:00 2001 From: David Ruiz Falco Date: Thu, 22 May 2025 10:40:58 +0200 Subject: [PATCH 1/5] add support for python 3.13 --- Cargo.lock | 165 ++++++++--------------------------------------------- Cargo.toml | 4 +- src/lib.rs | 75 ++++++++++++------------ 3 files changed, 63 insertions(+), 181 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f89b762..52173b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -17,12 +17,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "block-buffer" version = "0.10.4" @@ -79,9 +73,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indoc" @@ -124,16 +118,6 @@ version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "memchr" version = "2.6.4" @@ -155,29 +139,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "pest" version = "2.7.5" @@ -231,24 +192,24 @@ checksum = "da544ee218f0d287a911e9c99a39a8c9bc8fcad3cb8db5959940044ecfc67265" [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.21.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "e5203598f366b11a02b13aa20cab591229ff0a89fd121a308a5df751d5fc9219" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -258,9 +219,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "99636d423fa2ca130fa5acde3059308006d46f98caac629418e53f7ebb1e9999" dependencies = [ "once_cell", "target-lexicon", @@ -268,9 +229,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "78f9cf92ba9c409279bc3305b5409d90db2d2c22392d443a87df3a1adad59e33" dependencies = [ "libc", "pyo3-build-config", @@ -278,9 +239,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "0b999cb1a6ce21f9a6b147dcf1be9ffedf02e0043aec74dc390f3007047cecd9" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -290,9 +251,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "822ece1c7e1012745607d5cf0bcb2874769f0f7cb34c4cde03b9358eb9ef911a" dependencies = [ "heck", "proc-macro2", @@ -303,9 +264,9 @@ dependencies = [ [[package]] name = "pythonize" -version = "0.21.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d0664248812c38cc55a4ed07f88e4df516ce82604b93b1ffdc041aa77a6cb3c" +checksum = "d5bcac0d0b71821f0d69e42654f1e15e5c94b85196446c4de9588951a2117e7b" dependencies = [ "pyo3", "serde", @@ -313,22 +274,13 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.10.2" @@ -364,12 +316,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.190" @@ -412,17 +358,11 @@ dependencies = [ "digest", ] -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - [[package]] name = "syn" -version = "2.0.38" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -431,9 +371,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" [[package]] name = "thiserror" @@ -484,60 +424,3 @@ name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index 4fb1ebb..8ce944b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "jsonpath_rust_bindings" crate-type = ["cdylib"] [dependencies] -pyo3 = "0.21.2" +pyo3 = "0.24" jsonpath-rust = "0.7.0" serde_json = "1.0" -pythonize = "0.21.1" +pythonize = "0.24.0" diff --git a/src/lib.rs b/src/lib.rs index fc1893e..d0bec33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ use jsonpath_rust::{JsonPath, JsonPathValue}; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; -use pythonize::{depythonize_bound, pythonize}; +use pythonize::{depythonize, pythonize}; use serde_json::Value; #[pyclass(frozen)] @@ -32,10 +32,11 @@ struct Finder { impl Finder { #[new] fn py_new(obj: PyObject) -> PyResult { - Ok(Self { value: parse_py_object(obj)? }) + Ok(Self { + value: parse_py_object(obj)?, + }) } - fn find(self_: PyRef<'_, Self>, query: String) -> PyResult> { find_internal(&self_.value, &query, |_| true) } @@ -44,68 +45,67 @@ impl Finder { find_internal(&self_.value, &query, |v| match v { JsonPathValue::Slice(_, _) => true, JsonPathValue::NewValue(_) => true, - JsonPathValue::NoValue => false + JsonPathValue::NoValue => false, }) } } -fn find_internal(value: &Value, query: &str, predicate: impl Fn(&JsonPathValue) -> bool) -> PyResult> { +fn find_internal( + value: &Value, + query: &str, + predicate: impl Fn(&JsonPathValue) -> bool, +) -> PyResult> { let query = parse_query(query)?; let slice = query.find_slice(value).into_iter().filter(predicate); Python::with_gil(|py| { - slice.into_iter().map(|v| map_json_path_value(py, v)).collect() + slice + .into_iter() + .map(|v| map_json_path_value(py, v)) + .collect() }) } - fn map_json_path_value(py: Python, jpv: JsonPathValue) -> PyResult { Ok(match jpv { - JsonPathValue::Slice(data, path) => { - JsonPathResult { - data: Some(pythonize(py, data)?), - path: Some(path.to_string()), - is_new_value: false, - } - } - JsonPathValue::NewValue(data) => { - JsonPathResult { - data: Some(pythonize(py, &data)?), - path: None, - is_new_value: true, - } - } - JsonPathValue::NoValue => { - JsonPathResult { - data: None, - path: None, - is_new_value: false, - } - } + JsonPathValue::Slice(data, path) => JsonPathResult { + data: Some(pythonize(py, data)?.into_pyobject(py)?.unbind()), + path: Some(path.to_string()), + is_new_value: false, + }, + JsonPathValue::NewValue(data) => JsonPathResult { + data: Some(pythonize(py, &data)?.into_pyobject(py)?.unbind()), + path: None, + is_new_value: true, + }, + JsonPathValue::NoValue => JsonPathResult { + data: None, + path: None, + is_new_value: false, + }, }) } - fn parse_query(query: &str) -> PyResult { match JsonPath::try_from(query) { Ok(inst) => Ok(inst), - Err(err) => { - Err(PyValueError::new_err(format!("{err:?}"))) - } + Err(err) => Err(PyValueError::new_err(format!("{err:?}"))), } } fn parse_py_object(obj: PyObject) -> PyResult { Python::with_gil(|py| { let any = obj.downcast_bound::(py)?.clone().into_any(); - let value = depythonize_bound(any)?; + let value = depythonize(&any)?; Ok(value) }) } fn repr_json_path_result(slf: PyRef<'_, JsonPathResult>) -> PyResult { - let data_repr = slf.data.as_ref().map(|data| { - Python::with_gil(|py| format!("{:?}", data.bind(py))) - }).unwrap_or_default(); + let data_repr = slf + .data + .as_ref() + .map(|data| Python::with_gil(|py| format!("{:?}", data.bind(py)))) + .unwrap_or_default(); let path_repr = match &slf.path { Some(path) => path, @@ -117,9 +117,8 @@ fn repr_json_path_result(slf: PyRef<'_, JsonPathResult>) -> PyResult { )) } - #[pymodule] -fn jsonpath_rust_bindings(_py: Python, m: &PyModule) -> PyResult<()> { +fn jsonpath_rust_bindings(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; Ok(()) From a9939e6fb63f75f0cbca6b60da71b924d2c1fd4b Mon Sep 17 00:00:00 2001 From: David Ruiz Falco Date: Thu, 22 May 2025 10:44:39 +0200 Subject: [PATCH 2/5] update pyproject.toml --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 11ea0e3..8edc998 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,8 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ] From e98e6559f2ae6a444c62ddf6748d661cc2a19d5c Mon Sep 17 00:00:00 2001 From: David Ruiz Falco Date: Thu, 22 May 2025 11:00:10 +0200 Subject: [PATCH 3/5] update upload-artifact action to v4 --- .github/workflows/CI.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7658eb9..a957155 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -37,7 +37,7 @@ jobs: sccache: 'true' manylinux: auto - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wheels path: dist @@ -60,7 +60,7 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wheels path: dist @@ -82,7 +82,7 @@ jobs: args: --release --out dist --find-interpreter sccache: 'true' - name: Upload wheels - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wheels path: dist @@ -97,7 +97,7 @@ jobs: command: sdist args: --out dist - name: Upload sdist - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: wheels path: dist From e1433faf2a0dc0719a7a451578ac5b5dccef9836 Mon Sep 17 00:00:00 2001 From: David Ruiz Falco Date: Thu, 22 May 2025 11:51:36 +0200 Subject: [PATCH 4/5] fix CI --- .github/workflows/CI.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a957155..991d073 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,8 +25,8 @@ jobs: matrix: target: [x86_64, x86, aarch64, armv7, s390x, ppc64le] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - name: Build wheels @@ -39,7 +39,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-linux-${{ matrix.target }} path: dist windows: @@ -48,8 +48,8 @@ jobs: matrix: target: [x64, x86] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' architecture: ${{ matrix.target }} @@ -62,7 +62,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-windows-${{ matrix.target }} path: dist macos: @@ -71,8 +71,8 @@ jobs: matrix: target: [x86_64, aarch64] steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: '3.10' - name: Build wheels @@ -84,13 +84,13 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-macos-${{ matrix.target }} path: dist sdist: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build sdist uses: PyO3/maturin-action@v1 with: @@ -99,7 +99,7 @@ jobs: - name: Upload sdist uses: actions/upload-artifact@v4 with: - name: wheels + name: wheels-sdist path: dist release: @@ -108,13 +108,15 @@ jobs: if: "startsWith(github.ref, 'refs/tags/')" needs: [linux, windows, macos, sdist] steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: wheels + pattern: wheels-* + path: wheels + merge-multiple: true - name: Publish to PyPI uses: PyO3/maturin-action@v1 env: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: command: upload - args: --non-interactive --skip-existing * + args: --non-interactive --skip-existing wheels/* \ No newline at end of file From eefc16963756be975e39b68d91820e88dd4795ff Mon Sep 17 00:00:00 2001 From: David Ruiz Falco Date: Thu, 22 May 2025 11:55:40 +0200 Subject: [PATCH 5/5] test with python 3.12 and 3.13 --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a55101a..0d69b74 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,18 +4,17 @@ on: [ push ] jobs: build: - runs-on: ${{ matrix.os }} strategy: matrix: os: [ ubuntu-latest, macos-latest ] - python-version: [ "3.8", "3.9", "3.10", "3.11", "pypy3.9", "pypy3.10" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9", "pypy3.10" ] steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: ${{ matrix.python-version }} - name: Create virtualenv and install package run: | python -m venv env