From d01701615178124ffed664e026bae6727ca9ea01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Milkovi=C4=8D?= Date: Mon, 8 Dec 2025 19:42:20 +0100 Subject: [PATCH 1/2] chore: Update to latest pyo3 --- Cargo.lock | 149 +++++++---------------------------------- yari-py/Cargo.toml | 2 +- yari-py/pyproject.toml | 5 +- yari-py/src/lib.rs | 98 ++++++++++++++------------- 4 files changed, 80 insertions(+), 174 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a360a90..1458fc1 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 = "addr2line" @@ -237,9 +237,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[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 = "hermit-abi" @@ -321,16 +321,6 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" -[[package]] -name = "lock_api" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.21" @@ -399,9 +389,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.14.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "owo-colors" @@ -409,29 +399,6 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" -[[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.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys 0.36.1", -] - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -452,24 +419,23 @@ checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.20.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233" +checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d" dependencies = [ - "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -479,19 +445,18 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.20.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7" +checksum = "b455933107de8642b4487ed26d912c2d899dec6114884214a0b3bb3be9261ea6" dependencies = [ - "once_cell", "target-lexicon", ] [[package]] name = "pyo3-ffi" -version = "0.20.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa" +checksum = "1c85c9cbfaddf651b1221594209aed57e9e5cff63c4d11d1feead529b872a089" dependencies = [ "libc", "pyo3-build-config", @@ -499,27 +464,27 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.20.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158" +checksum = "0a5b10c9bf9888125d917fb4d2ca2d25c8df94c7ab5a52e13313a07e050a3b02" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.48", + "syn 2.0.111", ] [[package]] name = "pyo3-macros-backend" -version = "0.20.3" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185" +checksum = "03b51720d314836e53327f5871d4c0cfb4fb37cc2c4a11cc71907a86342c40f9" dependencies = [ "heck", "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.48", + "syn 2.0.111", ] [[package]] @@ -531,15 +496,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "regex" version = "1.10.3" @@ -614,12 +570,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "sharded-slab" version = "0.1.4" @@ -635,12 +585,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - [[package]] name = "strsim" version = "0.10.0" @@ -660,9 +604,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -671,9 +615,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.4" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1" +checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" [[package]] name = "termcolor" @@ -701,7 +645,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.111", ] [[package]] @@ -833,19 +777,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.45.0" @@ -906,12 +837,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - [[package]] name = "windows_aarch64_msvc" version = "0.42.1" @@ -924,12 +849,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - [[package]] name = "windows_i686_gnu" version = "0.42.1" @@ -942,12 +861,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - [[package]] name = "windows_i686_msvc" version = "0.42.1" @@ -960,12 +873,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - [[package]] name = "windows_x86_64_gnu" version = "0.42.1" @@ -990,12 +897,6 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "windows_x86_64_msvc" version = "0.42.1" diff --git a/yari-py/Cargo.toml b/yari-py/Cargo.toml index e2b4b8d..37ae159 100644 --- a/yari-py/Cargo.toml +++ b/yari-py/Cargo.toml @@ -11,5 +11,5 @@ name = "yari" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.20.3", features = ["extension-module"] } +pyo3 = { version = "0.27", features = ["extension-module"] } yari-sys = { path = "../yari-sys" } diff --git a/yari-py/pyproject.toml b/yari-py/pyproject.toml index 714b68d..52de8d0 100644 --- a/yari-py/pyproject.toml +++ b/yari-py/pyproject.toml @@ -1,10 +1,11 @@ [build-system] -requires = ["maturin>=0.13,<0.14"] +requires = ["maturin>=1.0,<2.0"] build-backend = "maturin" [project] name = "yari-py" -requires-python = ">=3.7" +requires-python = ">=3.8" +dynamic = ["version"] classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", diff --git a/yari-py/src/lib.rs b/yari-py/src/lib.rs index 875626b..6f661f0 100644 --- a/yari-py/src/lib.rs +++ b/yari-py/src/lib.rs @@ -1,8 +1,7 @@ use pyo3::create_exception; use pyo3::exceptions::PyException; use pyo3::prelude::*; -use pyo3::types::PyDict; -use pyo3::types::PyString; +use pyo3::types::{PyDict, PyList}; use std::collections::HashMap; use std::path::PathBuf; use std::str::FromStr; @@ -20,34 +19,43 @@ struct Context { inner: YARIContext, } -/// Helper to convert `YrValue` to a `PyObject`. +/// Helper to convert `YrValue` to a `Bound`. /// /// Return values are modeled similar to Python built-in `eval` function. This function converts /// values to the Python native types. For example `Vec` is converted to `list[YrValue]`. /// Same applies to structures and dictionaries. -fn yr_value_to_py_object(py: Python<'_>, yr_value: &YrValue) -> PyObject { +fn yr_value_to_py_object<'py>(py: Python<'py>, yr_value: &YrValue) -> Bound<'py, PyAny> { match yr_value { - YrValue::Integer(i) => i.into_py(py), - YrValue::Float(f) => f.into_py(py), - YrValue::String(s) => s.as_ref().into_py(py), - YrValue::Dictionary(d) => d - .iter() - .map(|(k, v)| (k, yr_value_to_py_object(py, v))) - .collect::>() - .into_py(py), - YrValue::Array(a) => a - .iter() - .map(|val| yr_value_to_py_object(py, val)) - .collect::>() - .into_py(py), - YrValue::Structure(s) => s - .as_ref() - .map(|map| { - map.iter() - .map(|(k, v)| (k, yr_value_to_py_object(py, v))) - .collect::>() - }) - .into_py(py), + YrValue::Integer(i) => (*i).into_pyobject(py).unwrap().into_any(), + YrValue::Float(f) => (*f).into_pyobject(py).unwrap().into_any(), + YrValue::String(s) => s.as_ref().into_pyobject(py).unwrap().into_any(), + YrValue::Dictionary(d) => { + let dict = PyDict::new(py); + for (k, v) in d.iter() { + let val = yr_value_to_py_object(py, v); + dict.set_item(k, val).unwrap(); + } + dict.into_any() + } + YrValue::Array(a) => { + let list = PyList::empty(py); + for val in a.iter() { + let py_val = yr_value_to_py_object(py, val); + list.append(py_val).unwrap(); + } + list.into_any() + } + YrValue::Structure(s) => match s.as_ref() { + Some(map) => { + let dict = PyDict::new(py); + for (k, v) in map.iter() { + let val = yr_value_to_py_object(py, v); + dict.set_item(k, val).unwrap(); + } + dict.into_any() + } + None => py.None().into_bound(py), + }, } } @@ -59,47 +67,42 @@ impl Context { /// any module data. `sample` and `rule` are expected to be valid paths. `module_data` is a /// python dictionary where key is a module name and data is a path to a file. #[new] + #[pyo3(signature = (sample=None, rule_string=None, rule_path=None, module_data=None))] fn new( - sample: Option<&PyString>, - rule_string: Option<&PyString>, - rule_path: Option<&PyString>, - module_data: Option<&PyDict>, + sample: Option, + rule_string: Option, + rule_path: Option, + module_data: Option>, ) -> PyResult { let mut builder = ContextBuilder::default(); if let Some(sample) = sample { - builder = builder.with_sample(Some(sample.to_string())); + builder = builder.with_sample(Some(sample)); } // Use either `rule_string` or `rule_path`. Invalid configuration of arguments raises // exception. match (rule_string, rule_path) { (Some(rule_string), None) => { - builder = builder.with_rule_string(Some(rule_string.to_string())) + builder = builder.with_rule_string(Some(rule_string)); } (None, Some(rule_path)) => { - builder = builder.with_rule_file(Some(rule_path.to_string())) + builder = builder.with_rule_file(Some(rule_path)); } (Some(_), Some(_)) => { return Err(YariError::new_err( - "detected Context with both `rule_string` and `rule_path`, specify only one of the sources".to_string(), + "detected Context with both `rule_string` and `rule_path`, specify only one" )) } - // Create empty context if no source was specified - (_, _) => {}, + (None, None) => {} } // Add the module data if let Some(module_data) = module_data { - for (module, data) in module_data { - if let (Ok(module), Ok(data)) = - (module.downcast::(), data.downcast::()) - { - let module = Module::from_str(module.to_str().unwrap()) - .map_err(|e| YariError::new_err(e.to_string()))?; - builder = - builder.with_module_data(module, PathBuf::from(data.to_str().unwrap())) - } + for (module_name, data_path) in module_data { + let module = Module::from_str(&module_name) + .map_err(|e| YariError::new_err(e.to_string()))?; + builder = builder.with_module_data(module, PathBuf::from(data_path)); } } @@ -114,7 +117,7 @@ impl Context { /// /// This function behaves like python build-in `eval` function and returns dynamic type based /// on the evaluation result. - pub fn eval(&mut self, py: Python<'_>, expr: &str) -> PyResult { + pub fn eval<'py>(&mut self, py: Python<'py>, expr: &str) -> PyResult> { self.inner .eval(expr) .as_ref() @@ -132,10 +135,11 @@ impl Context { } #[pymodule] -fn yari(py: Python, m: &PyModule) -> PyResult<()> { +fn yari(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; - m.add("YariError", py.get_type::())?; + // Add exception type + m.add("YariError", m.py().get_type::())?; m.add("LICENSES", yari_sys::LICENSES)?; From 872a7278a273ffb0c122a61a5739b83bb290ec0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Milkovi=C4=8D?= Date: Mon, 8 Dec 2025 19:42:53 +0100 Subject: [PATCH 2/2] ci: Run on windows-2022 where 19041 SDK is still installed + run against python 3.13 & 3.14 --- .github/workflows/build_wheels.yml | 6 +++--- .github/workflows/test.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index 8ea148e..9d10ef5 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -5,7 +5,7 @@ on: jobs: builder-windows: - runs-on: windows-latest + runs-on: windows-2022 defaults: run: shell: bash @@ -16,11 +16,11 @@ jobs: - uses: actions/setup-python@v5 with: python-version: | - 3.8 - 3.9 3.10 3.11 3.12 + 3.13 + 3.14 - name: Setup Nuget.exe uses: nuget/setup-nuget@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e11e27..8effefb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,7 +80,7 @@ jobs: .venv/bin/maturin develop .venv/bin/pytest build-windows: - runs-on: windows-latest + runs-on: windows-2022 defaults: run: shell: bash