From 6d13d4764f4749ae29df429ea29c8f25f3e27fa6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 8 Nov 2024 14:58:21 -0600 Subject: [PATCH] Upgrade to pyo3 0.21.2 --- Cargo.lock | 88 ++++++++++++++++++++++++++++++++++-------------------- Cargo.toml | 2 +- src/lib.rs | 17 +++++------ 3 files changed, 65 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ca0d57..8a2a1af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,7 +53,7 @@ checksum = "e21abe3434e1b78feb5fe14d30bf3fcfa0a3c599f0b8fb381302ee6f68eb5716" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -259,7 +259,7 @@ checksum = "3e7d0f888ea556a80f971cda6c897ce90ae0e7673fc1602eb2e9b86734e68768" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -406,6 +406,12 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.3" @@ -440,9 +446,9 @@ dependencies = [ [[package]] name = "indoc" -version = "1.0.9" +version = "2.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" [[package]] name = "inventory" @@ -609,6 +615,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "new_debug_unreachable" version = "1.0.4" @@ -725,6 +740,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -733,24 +754,25 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] [[package]] name = "pyo3" -version = "0.17.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543" +checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" dependencies = [ "cfg-if", "indoc", "libc", - "memoffset", + "memoffset 0.9.1", "parking_lot", + "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", @@ -759,9 +781,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.17.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8" +checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" dependencies = [ "once_cell", "target-lexicon", @@ -769,9 +791,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.17.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc" +checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" dependencies = [ "libc", "pyo3-build-config", @@ -779,32 +801,34 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.17.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28" +checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] name = "pyo3-macros-backend" -version = "0.17.3" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f" +checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" dependencies = [ + "heck", "proc-macro2", + "pyo3-build-config", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1002,7 +1026,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -1024,7 +1048,7 @@ checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -1061,7 +1085,7 @@ dependencies = [ "inventory", "itertools", "maplit", - "memoffset", + "memoffset 0.6.5", "num-bigint", "num-traits", "once_cell", @@ -1106,7 +1130,7 @@ dependencies = [ "dupe", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -1191,9 +1215,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -1202,9 +1226,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.12" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "term" @@ -1243,7 +1267,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.87", ] [[package]] @@ -1311,9 +1335,9 @@ checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "unindent" -version = "0.1.11" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" +checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" [[package]] name = "url" diff --git a/Cargo.toml b/Cargo.toml index 2103b92..a0081d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ name = "starlark" starlark = "^0.10.0" starlark_derive = "^0.10.0" anyhow = "^1.0.65" -pyo3 = { version = "0.17.1", features = ["extension-module"] } +pyo3 = { version = "0.21.2", features = ["extension-module"] } # needed to resolve contradictory constraints in dependencies syn = "^1.0.96" diff --git a/src/lib.rs b/src/lib.rs index fd444e3..7420aa8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,14 +97,14 @@ fn serde_to_starlark<'v>(x: serde_json::Value, heap: &'v Heap) -> anyhow::Result fn value_to_pyobject(value: Value) -> PyResult { let json_val = convert_err(value.to_json())?; Python::with_gil(|py| { - let json = py.import("json")?; + let json = py.import_bound("json")?; json.getattr("loads")?.call1((json_val,))?.extract() }) } fn pyobject_to_value<'v>(obj: PyObject, heap: &'v Heap) -> PyResult> { Python::with_gil(|py| -> PyResult> { - let json = py.import("json")?; + let json = py.import_bound("json")?; let json_str: String = json.getattr("dumps")?.call1((obj,))?.extract()?; convert_err(serde_to_starlark( convert_serde_err(serde_json::from_str(&json_str))?, @@ -633,7 +633,7 @@ impl<'v> StarlarkValue<'v> for PythonCallableValue { .map(|v| -> PyResult { value_to_pyobject(v) })) .collect::>>()?; convert_to_anyhow(pyobject_to_value( - self.callable.call1(py, PyTuple::new(py, py_args))?, + self.callable.call1(py, PyTuple::new_bound(py, py_args))?, eval.heap(), )) }) @@ -649,12 +649,12 @@ impl<'v> StarlarkValue<'v> for PythonCallableValue { /// .. automethod:: add_callable /// .. automethod:: freeze #[pyclass] -#[pyo3(text_signature = "() -> None")] struct Module(starlark::environment::Module); #[pymethods] impl Module { #[new] + #[pyo3(text_signature = "() -> None")] fn py_new() -> PyResult { Ok(Module(starlark::environment::Module::new())) } @@ -680,7 +680,6 @@ impl Module { self.0.set(name, b); } - #[pyo3(text_signature = "() -> FrozenModule")] fn freeze(mod_cell: &PyCell) -> PyResult { let module = mod_cell .replace(Module(starlark::environment::Module::new())) @@ -701,7 +700,6 @@ struct FrozenModule(starlark::environment::FrozenModule); // {{{ FileLoader #[pyclass] -#[pyo3(text_signature = "(load_func: Callable[[str], FrozenModule]) -> None")] struct FileLoader { callable: PyObject, } @@ -709,6 +707,7 @@ struct FileLoader { #[pymethods] impl FileLoader { #[new] + #[pyo3(text_signature = "(load_func: Callable[[str], FrozenModule]) -> None")] fn py_new(callable: PyObject) -> FileLoader { FileLoader { callable: callable } } @@ -755,7 +754,7 @@ fn eval( module: &mut Module, ast: &PyCell, globals: &Globals, - file_loader: Option<&PyCell>, + file_loader: Option<&Bound>, ) -> PyResult { let tail = |evaluator: &mut starlark::eval::Evaluator| { // Stupid: eval_module consumes the AST. @@ -783,7 +782,7 @@ fn eval( #[pymodule] #[pyo3(name = "starlark")] -fn starlark_py(_py: Python, m: &PyModule) -> PyResult<()> { +fn starlark_py(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -799,7 +798,7 @@ fn starlark_py(_py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_wrapped(wrap_pyfunction!(parse))?; m.add_wrapped(wrap_pyfunction!(eval))?; - m.add("StarlarkError", _py.get_type::())?; + m.add("StarlarkError", m.py().get_type_bound::())?; Ok(()) }