Skip to content

Commit

Permalink
Bump PyO3 to 0.20 (#110)
Browse files Browse the repository at this point in the history
* tokio_test: add panic message into exception string

* test adding module to export panic type

* get compiling

* fix macros build

* Fix some stuff

* fix build for async_std and tokio

* Bump PyO3 to 0.20

* Fixed compilation errors in panic message change

* Bumped MSRV

* Updated docs

---------

Co-authored-by: Chris Gregory <[email protected]>
Co-authored-by: Giovanni Barillari <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2023
1 parent 0ce6d6d commit 398ed30
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 45 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
platform: { os: "windows-latest", python-architecture: "x86" }
include:
# Test minimal supported Rust version
- rust: 1.62.0
- rust: 1.63.0
python-version: "3.10"
platform:
{
Expand Down Expand Up @@ -155,9 +155,6 @@ jobs:
env:
RUST_BACKTRACE: 1
RUSTFLAGS: "-D warnings"
# TODO: this is a hack to workaround compile_error! warnings about auto-initialize on PyPy
# Once cargo's `resolver = "2"` is stable (~ MSRV Rust 1.52), remove this.
PYO3_CI: 1

coverage:
needs: [fmt]
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-asyncio"
description = "PyO3 utilities for Python's Asyncio library"
version = "0.19.0"
version = "0.20.0"
authors = ["Andrew J Westlake <[email protected]>"]
readme = "README.md"
keywords = ["pyo3", "python", "ffi", "async", "asyncio"]
Expand Down Expand Up @@ -116,11 +116,11 @@ futures = "0.3"
inventory = { version = "0.3", optional = true }
once_cell = "1.14"
pin-project-lite = "0.2"
pyo3 = "0.19"
pyo3-asyncio-macros = { path = "pyo3-asyncio-macros", version = "=0.19.0", optional = true }
pyo3 = "0.20"
pyo3-asyncio-macros = { path = "pyo3-asyncio-macros", version = "=0.20.0", optional = true }

[dev-dependencies]
pyo3 = { version = "0.19", features = ["macros"] }
pyo3 = { version = "0.20", features = ["macros"] }

[dependencies.async-std]
version = "1.12"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Actions Status](https://github.com/awestlake87/pyo3-asyncio/workflows/CI/badge.svg)](https://github.com/awestlake87/pyo3-asyncio/actions)
[![codecov](https://codecov.io/gh/awestlake87/pyo3-asyncio/branch/master/graph/badge.svg)](https://codecov.io/gh/awestlake87/pyo3-asyncio)
[![crates.io](https://img.shields.io/crates/v/pyo3-asyncio)](https://crates.io/crates/pyo3-asyncio)
[![minimum rustc 1.62](https://img.shields.io/badge/rustc-1.62+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)
[![minimum rustc 1.63](https://img.shields.io/badge/rustc-1.63+-blue.svg)](https://rust-lang.github.io/rfcs/2495-min-rust-version.html)

[Rust](http://www.rust-lang.org/) bindings for [Python](https://www.python.org/)'s [Asyncio Library](https://docs.python.org/3/library/asyncio.html). This crate facilitates interactions between Rust Futures and Python Coroutines and manages the lifecycle of their corresponding event loops.

Expand Down Expand Up @@ -52,8 +52,8 @@ Here we initialize the runtime, import Python's `asyncio` library and run the gi
```toml
# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.19" }
pyo3-asyncio = { version = "0.19", features = ["attributes", "async-std-runtime"] }
pyo3 = { version = "0.20" }
pyo3-asyncio = { version = "0.20", features = ["attributes", "async-std-runtime"] }
async-std = "1.9"
```

Expand Down Expand Up @@ -82,8 +82,8 @@ attribute.
```toml
# Cargo.toml dependencies
[dependencies]
pyo3 = { version = "0.19" }
pyo3-asyncio = { version = "0.19", features = ["attributes", "tokio-runtime"] }
pyo3 = { version = "0.20" }
pyo3-asyncio = { version = "0.20", features = ["attributes", "tokio-runtime"] }
tokio = "1.9"
```

Expand Down Expand Up @@ -127,17 +127,17 @@ For `async-std`:

```toml
[dependencies]
pyo3 = { version = "0.19", features = ["extension-module"] }
pyo3-asyncio = { version = "0.19", features = ["async-std-runtime"] }
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["async-std-runtime"] }
async-std = "1.9"
```

For `tokio`:

```toml
[dependencies]
pyo3 = { version = "0.19", features = ["extension-module"] }
pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
tokio = "1.9"
```

Expand Down Expand Up @@ -431,8 +431,8 @@ name = "my_async_module"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.19", features = ["extension-module"] }
pyo3-asyncio = { version = "0.19", features = ["tokio-runtime"] }
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
async-std = "1.9"
tokio = "1.9"
```
Expand Down Expand Up @@ -491,8 +491,8 @@ event loop before we can install the `uvloop` policy.
```toml
[dependencies]
async-std = "1.9"
pyo3 = "0.19"
pyo3-asyncio = { version = "0.19", features = ["async-std-runtime"] }
pyo3 = "0.20"
pyo3-asyncio = { version = "0.20", features = ["async-std-runtime"] }
```

```rust no_run
Expand Down
4 changes: 2 additions & 2 deletions pyo3-asyncio-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pyo3-asyncio-macros"
description = "Proc Macro Attributes for PyO3 Asyncio"
version = "0.19.0"
version = "0.20.0"
authors = ["Andrew J Westlake <[email protected]>"]
readme = "../README.md"
keywords = ["pyo3", "python", "ffi", "async", "asyncio"]
Expand All @@ -18,4 +18,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1"
syn = { version = "1", features = ["full"] }
syn = { version = "1", features = ["full"] }
20 changes: 18 additions & 2 deletions pyo3-asyncio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@ pub fn tokio_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
Ok(result) => result,
Err(e) => {
assert!(e.is_panic());
Err(pyo3::exceptions::PyException::new_err("rust future panicked"))
let panic = e.into_panic();
let panic_message = if let Some(s) = panic.downcast_ref::<&str>() {
s.to_string()
} else if let Some(s) = panic.downcast_ref::<String>() {
s.clone()
} else {
"unknown error".into()
};
Err(pyo3_asyncio::err::RustPanic::new_err(format!("rust future panicked: {}", panic_message)))
}
}
})
Expand All @@ -265,7 +273,15 @@ pub fn tokio_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
Ok(result) => result,
Err(e) => {
assert!(e.is_panic());
Err(pyo3::exceptions::PyException::new_err("rust future panicked"))
let panic = e.into_panic();
let panic_message = if let Some(s) = panic.downcast_ref::<&str>() {
s.to_string()
} else if let Some(s) = panic.downcast_ref::<String>() {
s.clone()
} else {
"unknown error".into()
};
Err(pyo3_asyncio::err::RustPanic::new_err(format!("rust future panicked: {}", panic_message)))
}
}
})
Expand Down
5 changes: 4 additions & 1 deletion src/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//!
//! ```toml
//! [dependencies.pyo3-asyncio]
//! version = "0.19"
//! version = "0.20"
//! features = ["unstable-streams"]
//! ```
Expand Down Expand Up @@ -48,6 +48,9 @@ impl JoinError for AsyncStdJoinErr {
fn is_panic(&self) -> bool {
true
}
fn into_panic(self) -> Box<dyn Any + Send + 'static> {
self.0
}
}

async_std::task_local! {
Expand Down
Loading

0 comments on commit 398ed30

Please sign in to comment.