From 562ea403b34b39908f80ab7bc2daa69066cf9365 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 27 Oct 2020 19:57:14 -0400 Subject: [PATCH] Update to PyO3 0.12 + cargo raze by Damien --- cargo/BUILD.bazel | 2 +- cargo/Cargo.lock | 12 ++++---- cargo/crates.bzl | 30 +++++++++---------- cargo/raze.toml | 2 +- ....1.BUILD.bazel => pyo3-0.12.3.BUILD.bazel} | 9 ++++-- ...=> pyo3-derive-backend-0.12.3.BUILD.bazel} | 2 +- ...BUILD.bazel => pyo3cls-0.12.3.BUILD.bazel} | 4 +-- cargo/update.py | 6 ++-- pylib/rsbridge/Cargo.toml | 2 +- pylib/rsbridge/lib.rs | 12 ++++---- 10 files changed, 43 insertions(+), 38 deletions(-) rename cargo/remote/{pyo3-0.11.1.BUILD.bazel => pyo3-0.12.3.BUILD.bazel} (93%) rename cargo/remote/{pyo3-derive-backend-0.11.1.BUILD.bazel => pyo3-derive-backend-0.12.3.BUILD.bazel} (97%) rename cargo/remote/{pyo3cls-0.11.1.BUILD.bazel => pyo3cls-0.12.3.BUILD.bazel} (92%) diff --git a/cargo/BUILD.bazel b/cargo/BUILD.bazel index 83474b943..cb92bbcd4 100644 --- a/cargo/BUILD.bazel +++ b/cargo/BUILD.bazel @@ -248,7 +248,7 @@ alias( alias( name = "pyo3", - actual = "@raze__pyo3__0_11_1//:pyo3", + actual = "@raze__pyo3__0_12_3//:pyo3", tags = [ "cargo-raze", "manual", diff --git a/cargo/Cargo.lock b/cargo/Cargo.lock index edd12040d..05d749e81 100644 --- a/cargo/Cargo.lock +++ b/cargo/Cargo.lock @@ -1573,9 +1573,9 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.11.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ca8710ffa8211c9a62a8a3863c4267c710dc42a82a7fd29c97de465d7ea6b7d" +checksum = "a9b90d637542bbf29b140fdd38fa308424073fd2cdf641a5680aed8020145e3c" dependencies = [ "ctor", "indoc", @@ -1589,9 +1589,9 @@ dependencies = [ [[package]] name = "pyo3-derive-backend" -version = "0.11.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ad070bf6967b0d29ea74931ffcf9c6bbe8402a726e9afbeafadc0a287cc2b3" +checksum = "cee2c9fb095acb885ab7e85acc7c8e95da8c4bc7cc4b4ea64b566dfc8c91046a" dependencies = [ "proc-macro2", "quote", @@ -1600,9 +1600,9 @@ dependencies = [ [[package]] name = "pyo3cls" -version = "0.11.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fa17e1ea569d0bf3b7c00f2a9eea831ca05e55dd76f1794c541abba1c64baa" +checksum = "f12fdd8a2f217d003c93f9819e3db1717b2e89530171edea4c0deadd90206f50" dependencies = [ "pyo3-derive-backend", "quote", diff --git a/cargo/crates.bzl b/cargo/crates.bzl index 1fc211a2c..ff0d715e9 100644 --- a/cargo/crates.bzl +++ b/cargo/crates.bzl @@ -1624,32 +1624,32 @@ def raze_fetch_remote_crates(): maybe( http_archive, - name = "raze__pyo3__0_11_1", - url = "https://crates.io/api/v1/crates/pyo3/0.11.1/download", + name = "raze__pyo3__0_12_3", + url = "https://crates.io/api/v1/crates/pyo3/0.12.3/download", type = "tar.gz", - sha256 = "9ca8710ffa8211c9a62a8a3863c4267c710dc42a82a7fd29c97de465d7ea6b7d", - strip_prefix = "pyo3-0.11.1", - build_file = Label("//cargo/remote:pyo3-0.11.1.BUILD.bazel"), + sha256 = "a9b90d637542bbf29b140fdd38fa308424073fd2cdf641a5680aed8020145e3c", + strip_prefix = "pyo3-0.12.3", + build_file = Label("//cargo/remote:pyo3-0.12.3.BUILD.bazel"), ) maybe( http_archive, - name = "raze__pyo3_derive_backend__0_11_1", - url = "https://crates.io/api/v1/crates/pyo3-derive-backend/0.11.1/download", + name = "raze__pyo3_derive_backend__0_12_3", + url = "https://crates.io/api/v1/crates/pyo3-derive-backend/0.12.3/download", type = "tar.gz", - sha256 = "58ad070bf6967b0d29ea74931ffcf9c6bbe8402a726e9afbeafadc0a287cc2b3", - strip_prefix = "pyo3-derive-backend-0.11.1", - build_file = Label("//cargo/remote:pyo3-derive-backend-0.11.1.BUILD.bazel"), + sha256 = "cee2c9fb095acb885ab7e85acc7c8e95da8c4bc7cc4b4ea64b566dfc8c91046a", + strip_prefix = "pyo3-derive-backend-0.12.3", + build_file = Label("//cargo/remote:pyo3-derive-backend-0.12.3.BUILD.bazel"), ) maybe( http_archive, - name = "raze__pyo3cls__0_11_1", - url = "https://crates.io/api/v1/crates/pyo3cls/0.11.1/download", + name = "raze__pyo3cls__0_12_3", + url = "https://crates.io/api/v1/crates/pyo3cls/0.12.3/download", type = "tar.gz", - sha256 = "c3fa17e1ea569d0bf3b7c00f2a9eea831ca05e55dd76f1794c541abba1c64baa", - strip_prefix = "pyo3cls-0.11.1", - build_file = Label("//cargo/remote:pyo3cls-0.11.1.BUILD.bazel"), + sha256 = "f12fdd8a2f217d003c93f9819e3db1717b2e89530171edea4c0deadd90206f50", + strip_prefix = "pyo3cls-0.12.3", + build_file = Label("//cargo/remote:pyo3cls-0.12.3.BUILD.bazel"), ) maybe( diff --git a/cargo/raze.toml b/cargo/raze.toml index 9622044f2..2d4893059 100644 --- a/cargo/raze.toml +++ b/cargo/raze.toml @@ -22,7 +22,7 @@ targets = [ genmode = "Remote" default_gen_buildrs = true -[raze.crates.pyo3.'0.11.1'] +[raze.crates.pyo3.'0.12.3'] data_attr = "glob([\"**\"])" [raze.crates.ring.'0.16.15'] diff --git a/cargo/remote/pyo3-0.11.1.BUILD.bazel b/cargo/remote/pyo3-0.12.3.BUILD.bazel similarity index 93% rename from cargo/remote/pyo3-0.11.1.BUILD.bazel rename to cargo/remote/pyo3-0.12.3.BUILD.bazel index fe2058ec6..a42aac6b8 100644 --- a/cargo/remote/pyo3-0.11.1.BUILD.bazel +++ b/cargo/remote/pyo3-0.12.3.BUILD.bazel @@ -64,13 +64,14 @@ cargo_build_script( "cargo-raze", "manual", ], - version = "0.11.1", + version = "0.12.3", visibility = ["//visibility:private"], ) # Unsupported target "bench_dict" with type "bench" omitted # Unsupported target "bench_list" with type "bench" omitted # Unsupported target "bench_pyobject" with type "bench" omitted +# Unsupported target "bench_set" with type "bench" omitted # Unsupported target "bench_tuple" with type "bench" omitted # Unsupported target "common" with type "test" omitted @@ -92,13 +93,13 @@ rust_library( edition = "2018", proc_macro_deps = [ "@raze__ctor__0_1_16//:ctor", - "@raze__pyo3cls__0_11_1//:pyo3cls", + "@raze__pyo3cls__0_12_3//:pyo3cls", ], rustc_flags = [ "--cap-lints=allow", ], data = glob(["**"]), - version = "0.11.1", + version = "0.12.3", tags = [ "cargo-raze", "manual", @@ -127,6 +128,7 @@ rust_library( # Unsupported target "test_dict_iter" with type "test" omitted # Unsupported target "test_dunder" with type "test" omitted # Unsupported target "test_exceptions" with type "test" omitted +# Unsupported target "test_frompyobject" with type "test" omitted # Unsupported target "test_gc" with type "test" omitted # Unsupported target "test_getter_setter" with type "test" omitted # Unsupported target "test_inheritance" with type "test" omitted @@ -138,5 +140,6 @@ rust_library( # Unsupported target "test_sequence" with type "test" omitted # Unsupported target "test_string" with type "test" omitted # Unsupported target "test_text_signature" with type "test" omitted +# Unsupported target "test_unsendable_dict" with type "test" omitted # Unsupported target "test_variable_arguments" with type "test" omitted # Unsupported target "test_various" with type "test" omitted diff --git a/cargo/remote/pyo3-derive-backend-0.11.1.BUILD.bazel b/cargo/remote/pyo3-derive-backend-0.12.3.BUILD.bazel similarity index 97% rename from cargo/remote/pyo3-derive-backend-0.11.1.BUILD.bazel rename to cargo/remote/pyo3-derive-backend-0.12.3.BUILD.bazel index 601a40eb0..a55282645 100644 --- a/cargo/remote/pyo3-derive-backend-0.11.1.BUILD.bazel +++ b/cargo/remote/pyo3-derive-backend-0.12.3.BUILD.bazel @@ -45,7 +45,7 @@ rust_library( rustc_flags = [ "--cap-lints=allow", ], - version = "0.11.1", + version = "0.12.3", tags = [ "cargo-raze", "manual", diff --git a/cargo/remote/pyo3cls-0.11.1.BUILD.bazel b/cargo/remote/pyo3cls-0.12.3.BUILD.bazel similarity index 92% rename from cargo/remote/pyo3cls-0.11.1.BUILD.bazel rename to cargo/remote/pyo3cls-0.12.3.BUILD.bazel index d69d38f29..a34fb662d 100644 --- a/cargo/remote/pyo3cls-0.11.1.BUILD.bazel +++ b/cargo/remote/pyo3cls-0.12.3.BUILD.bazel @@ -35,7 +35,7 @@ rust_library( name = "pyo3cls", crate_type = "proc-macro", deps = [ - "@raze__pyo3_derive_backend__0_11_1//:pyo3_derive_backend", + "@raze__pyo3_derive_backend__0_12_3//:pyo3_derive_backend", "@raze__quote__1_0_7//:quote", "@raze__syn__1_0_48//:syn", ], @@ -45,7 +45,7 @@ rust_library( rustc_flags = [ "--cap-lints=allow", ], - version = "0.11.1", + version = "0.12.3", tags = [ "cargo-raze", "manual", diff --git a/cargo/update.py b/cargo/update.py index b09aac81f..8a0664546 100644 --- a/cargo/update.py +++ b/cargo/update.py @@ -6,7 +6,8 @@ # EXTRA_DEPS = [ - 'pyo3 = { version = "0.11.0", features = ["extension-module"] }' + # when updating, the version number in raze.toml will need updating too + 'pyo3 = { version = "0.12.0", features = ["extension-module"] }' ] import os @@ -39,6 +40,7 @@ with open("Cargo.toml", "w") as file: file.write("\n".join(deps)) subprocess.run(["cargo", "update"], check=True) -shutil.rmtree("remote") +if os.path.exists("remote"): + shutil.rmtree("remote") subprocess.run(["cargo-raze"], check=True) os.remove("Cargo.toml") diff --git a/pylib/rsbridge/Cargo.toml b/pylib/rsbridge/Cargo.toml index a063cbdb7..42469218a 100644 --- a/pylib/rsbridge/Cargo.toml +++ b/pylib/rsbridge/Cargo.toml @@ -12,7 +12,7 @@ anki = { path = "../../rslib" } # WARNING: if changing the version number here, the version in ../../cargo/update.py # needs to be updated as well [dependencies.pyo3] -version = "0.11.0" +version = "0.12.0" features = ["extension-module"] [lib] diff --git a/pylib/rsbridge/lib.rs b/pylib/rsbridge/lib.rs index 747593cbc..2f5583079 100644 --- a/pylib/rsbridge/lib.rs +++ b/pylib/rsbridge/lib.rs @@ -2,10 +2,10 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html use anki::backend::{init_backend, Backend as RustBackend, BackendMethod}; -use pyo3::exceptions::Exception; +use pyo3::exceptions::PyException; use pyo3::prelude::*; use pyo3::types::PyBytes; -use pyo3::{create_exception, exceptions, wrap_pyfunction}; +use pyo3::{create_exception, wrap_pyfunction}; use std::convert::TryFrom; // Regular backend @@ -16,7 +16,7 @@ struct Backend { backend: RustBackend, } -create_exception!(_rsbridge, BackendError, Exception); +create_exception!(_rsbridge, BackendError, PyException); #[pyfunction] fn buildhash() -> &'static str { @@ -27,7 +27,7 @@ fn buildhash() -> &'static str { fn open_backend(init_msg: &PyBytes) -> PyResult { match init_backend(init_msg.as_bytes()) { Ok(backend) => Ok(Backend { backend }), - Err(e) => Err(exceptions::Exception::py_err(e)), + Err(e) => Err(PyException::new_err(e)), } } @@ -72,7 +72,7 @@ impl Backend { let out_obj = PyBytes::new(py, &out_bytes); out_obj.into() }) - .map_err(BackendError::py_err) + .map_err(BackendError::new_err) } /// This takes and returns JSON, due to Python's slow protobuf @@ -82,7 +82,7 @@ impl Backend { let out_res = py.allow_threads(|| { self.backend .run_db_command_bytes(in_bytes) - .map_err(BackendError::py_err) + .map_err(BackendError::new_err) }); let out_bytes = out_res?; let out_obj = PyBytes::new(py, &out_bytes);