From 2cb3a17474267df69289d7dc6ed860bf9dc7253b Mon Sep 17 00:00:00 2001 From: arty Date: Wed, 24 Jan 2024 20:57:41 -0800 Subject: [PATCH] Upgrade pyo3 and maturin --- Cargo.lock | 118 ++++++++++++++++++++++-------------------------- Cargo.toml | 2 +- pyproject.toml | 2 +- src/py/api.rs | 34 ++++++++------ src/py/pyval.rs | 26 +++++------ 5 files changed, 88 insertions(+), 94 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37316ff4d..5e9d41ed5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -492,6 +492,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" @@ -532,16 +538,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "indoc" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47741a8bc60fb26eb8d6e0238bbb26d8575ff623fdc97b1a2c00c050b9684ed8" -dependencies = [ - "indoc-impl", - "proc-macro-hack", -] - [[package]] name = "indoc" version = "1.0.9" @@ -549,17 +545,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" [[package]] -name = "indoc-impl" -version = "0.3.6" +name = "indoc" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce046d161f000fffde5f432a0d034d0341dc152643b2598ed5bfce44c4f3a8f0" -dependencies = [ - "proc-macro-hack", - "proc-macro2 1.0.66", - "quote 1.0.32", - "syn 1.0.109", - "unindent", -] +checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8" [[package]] name = "instant" @@ -709,6 +698,15 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "num" version = "0.4.1" @@ -854,25 +852,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", -] - [[package]] name = "pbkdf2" version = "0.11.0" @@ -926,12 +905,6 @@ dependencies = [ "toml_edit", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" - [[package]] name = "proc-macro2" version = "0.4.30" @@ -952,59 +925,72 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.14.5" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35100f9347670a566a67aa623369293703322bb9db77d99d7df7313b575ae0c8" +checksum = "9a89dc7a5850d0e983be1ec2a463a171d20990487c3cfcd68b5363f1ee3d6fe0" dependencies = [ "cfg-if", - "indoc 0.3.6", + "indoc 2.0.4", "libc", + "memoffset", "parking_lot", - "paste", - "pyo3-build-config 0.14.5", + "pyo3-build-config 0.20.2", + "pyo3-ffi", "pyo3-macros", "unindent", ] [[package]] name = "pyo3-build-config" -version = "0.14.5" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d12961738cacbd7f91b7c43bc25cfeeaa2698ad07a04b3be0aa88b950865738f" +checksum = "779239fc40b8e18bc8416d3a37d280ca9b9fb04bda54b98037bb6748595c2410" dependencies = [ "once_cell", ] [[package]] name = "pyo3-build-config" -version = "0.15.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "779239fc40b8e18bc8416d3a37d280ca9b9fb04bda54b98037bb6748595c2410" +checksum = "07426f0d8fe5a601f26293f300afd1a7b1ed5e78b2a705870c5f30893c5163be" dependencies = [ "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb7dec17e17766b46bca4f1a4215a85006b4c2ecde122076c562dd058da6cf1" +dependencies = [ + "libc", + "pyo3-build-config 0.20.2", ] [[package]] name = "pyo3-macros" -version = "0.14.5" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0bc5215d704824dfddddc03f93cb572e1155c68b6761c37005e1c288808ea8" +checksum = "05f738b4e40d50b5711957f142878cfa0f28e054aa0ebdfc3fd137a843f74ed3" dependencies = [ + "proc-macro2 1.0.66", "pyo3-macros-backend", "quote 1.0.32", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] name = "pyo3-macros-backend" -version = "0.14.5" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71623fc593224afaab918aa3afcaf86ed2f43d34f6afde7f3922608f253240df" +checksum = "0fc910d4851847827daf9d6cdd4a823fbdaab5b8818325c5e97a86da79e8881f" dependencies = [ + "heck", "proc-macro2 1.0.66", - "pyo3-build-config 0.14.5", "quote 1.0.32", - "syn 1.0.109", + "syn 2.0.28", ] [[package]] @@ -1295,6 +1281,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "target-lexicon" +version = "0.12.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" + [[package]] name = "tempfile" version = "3.7.0" @@ -1423,9 +1415,9 @@ checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" [[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 = "version_check" diff --git a/Cargo.toml b/Cargo.toml index 9da5e32c7..6df76426d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } regex = "1.8.4" [dependencies.pyo3] -version = "0.14.2" +version = "0.20.2" features = ["abi3-py38", "extension-module"] optional = true diff --git a/pyproject.toml b/pyproject.toml index 6049eb79b..45e59490c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["maturin>=1.1.0,<1.3.0"] +requires = ["maturin>=1.3.2,<1.4.0"] build-backend = "maturin" [tool.maturin] diff --git a/src/py/api.rs b/src/py/api.rs index 2a4722548..c16e6606c 100644 --- a/src/py/api.rs +++ b/src/py/api.rs @@ -50,7 +50,8 @@ fn get_version() -> PyResult { Ok(version()) } -#[pyfunction(arg3 = "[]", arg4 = "None")] +#[pyfunction] +#[pyo3(signature = (input_path, output_path, search_paths = Vec::new(), export_symbols = None))] fn compile_clvm( input_path: &PyAny, output_path: String, @@ -93,7 +94,8 @@ fn compile_clvm( }) } -#[pyfunction(arg2 = "[]")] +#[pyfunction] +#[pyo3(signature = (input_path, search_paths=Vec::new()))] fn check_dependencies(input_path: &PyAny, search_paths: Vec) -> PyResult { let has_atom = input_path.hasattr("atom")?; let has_pair = input_path.hasattr("pair")?; @@ -202,12 +204,14 @@ impl CldbSingleBespokeOverride for CldbSinglePythonOverride { .pycode .call1(py, PyTuple::new(py, &vec![arg_value])) .map_err(|e| RunFailure::RunErr(env.loc(), format!("{}", e)))?; - python_value_to_clvm(py, res) + let res_ref: &PyAny = res.as_ref(py); + python_value_to_clvm(res_ref) }) } } -#[pyfunction(arg4 = "None", arg5 = "None")] +#[pyfunction] +#[pyo3(signature = (hex_prog, hex_args, symbol_table, overrides=None, run_options=None))] fn start_clvm_program( hex_prog: String, hex_args: String, @@ -218,17 +222,18 @@ fn start_clvm_program( let (command_tx, command_rx) = mpsc::channel(); let (result_tx, result_rx) = mpsc::channel(); - let gil = Python::acquire_gil(); - let py = gil.python(); + let print_only_value = Python::with_gil(|py| { + let print_only_option = run_options + .and_then(|h| h.get("print").map(|p| p.clone())) + .unwrap_or_else(|| { + let any: Py = PyBool::new(py, false).into(); + any + }); - let print_only_option = run_options - .and_then(|h| h.get("print").map(|p| p.clone())) - .unwrap_or_else(|| { - let any: Py = PyBool::new(py, false).into(); - any - }); + PyBool::new(py, true).compare(print_only_option) + })?; - let print_only = PyBool::new(py, true).compare(print_only_option)? == Ordering::Equal; + let print_only = print_only_value == Ordering::Equal; thread::spawn(move || { let mut allocator = Allocator::new(); @@ -306,7 +311,8 @@ fn start_clvm_program( }) } -#[pyfunction(arg3 = 2)] +#[pyfunction] +#[pyo3(signature = (tool_name, args, default_stage=2))] fn launch_tool(tool_name: String, args: Vec, default_stage: u32) -> Vec { let mut stdout = Stream::new(None); cmds::launch_tool(&mut stdout, &args, &tool_name, default_stage); diff --git a/src/py/pyval.rs b/src/py/pyval.rs index 117bd67ad..546342a9c 100644 --- a/src/py/pyval.rs +++ b/src/py/pyval.rs @@ -11,14 +11,13 @@ use crate::compiler::runtypes::RunFailure; use crate::compiler::sexp::SExp; use crate::compiler::srcloc::Srcloc; -pub fn map_err_to_pyerr(srcloc: Srcloc, r: PyResult>) -> Result, RunFailure> { +pub fn map_err_to_pyerr(srcloc: Srcloc, r: PyResult) -> Result { r.map_err(|e| RunFailure::RunErr(srcloc, format!("{e}"))) } -pub fn python_value_to_clvm(py: Python, val: Py) -> Result, RunFailure> { +pub fn python_value_to_clvm(val: &PyAny) -> Result, RunFailure> { let srcloc = Srcloc::start("*python*"); - val.as_ref(py) - .downcast::() + val.downcast::() .ok() .map(|l| { if l.is_empty() { @@ -27,11 +26,10 @@ pub fn python_value_to_clvm(py: Python, val: Py) -> Result, RunF let mut result = SExp::Nil(srcloc.clone()); for i_rev in 0..l.len() { let i = l.len() - i_rev - 1; - let item = l.get_item(i as isize).extract(); - let any_of_elt = map_err_to_pyerr(srcloc.clone(), item)?; + let any_of_elt = map_err_to_pyerr(srcloc.clone(), l.get_item(i))?; result = SExp::Cons( srcloc.clone(), - python_value_to_clvm(py, any_of_elt)?, + python_value_to_clvm(any_of_elt)?, Rc::new(result), ); } @@ -40,8 +38,7 @@ pub fn python_value_to_clvm(py: Python, val: Py) -> Result, RunF }) .map(Some) .unwrap_or_else(|| { - val.as_ref(py) - .downcast::() + val.downcast::() .map(|t| { if t.len() != 2 { Err(RunFailure::RunErr( @@ -49,12 +46,12 @@ pub fn python_value_to_clvm(py: Python, val: Py) -> Result, RunF "tuple must have len 2".to_string(), )) } else { - let any_of_e0 = map_err_to_pyerr(srcloc.clone(), t.get_item(0).extract())?; - let any_of_e1 = map_err_to_pyerr(srcloc.clone(), t.get_item(1).extract())?; + let any_of_e0 = map_err_to_pyerr(srcloc.clone(), t.get_item(0))?; + let any_of_e1 = map_err_to_pyerr(srcloc.clone(), t.get_item(1))?; Ok(Rc::new(SExp::Cons( srcloc.clone(), - python_value_to_clvm(py, any_of_e0)?, - python_value_to_clvm(py, any_of_e1)?, + python_value_to_clvm(any_of_e0)?, + python_value_to_clvm(any_of_e1)?, ))) } }) @@ -62,8 +59,7 @@ pub fn python_value_to_clvm(py: Python, val: Py) -> Result, RunF }) .map(Some) .unwrap_or_else(|| { - val.as_ref(py) - .downcast::() + val.downcast::() .map(|b| Ok(Rc::new(SExp::Atom(srcloc.clone(), b.as_bytes().to_vec())))) .ok() })