Skip to content

Commit 4ab275c

Browse files
authored
Bump to 0.23 (#21)
* Bump to 0.23 * Attempt to bump to 0.23 * Another approach * update * fix compile! * move cstring inside conditional import * address comment * update examples and tests * Update docstrings * fixes
1 parent b3fcc86 commit 4ab275c

21 files changed

+285
-237
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pyo3-async-runtimes"
33
description = "PyO3 bridges from Rust runtimes to Python's Asyncio library"
4-
version = "0.22.0"
4+
version = "0.23.0"
55
authors = [
66
"Andrew J Westlake <[email protected]>",
77
"David Hewitt <[email protected]>",
@@ -120,11 +120,11 @@ futures = "0.3"
120120
inventory = { version = "0.3", optional = true }
121121
once_cell = "1.14"
122122
pin-project-lite = "0.2"
123-
pyo3 = "0.22"
124-
pyo3-async-runtimes-macros = { path = "pyo3-async-runtimes-macros", version = "=0.22.0", optional = true }
123+
pyo3 = "0.23"
124+
pyo3-async-runtimes-macros = { path = "pyo3-async-runtimes-macros", version = "=0.23.0", optional = true }
125125

126126
[dev-dependencies]
127-
pyo3 = { version = "0.22", features = ["macros"] }
127+
pyo3 = { version = "0.23", features = ["macros"] }
128128

129129
[dependencies.async-std]
130130
version = "1.12"

README.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Here we initialize the runtime, import Python's `asyncio` library and run the gi
5454
```toml
5555
# Cargo.toml dependencies
5656
[dependencies]
57-
pyo3 = { version = "0.22" }
58-
pyo3-async-runtimes = { version = "0.22", features = ["attributes", "async-std-runtime"] }
57+
pyo3 = { version = "0.23" }
58+
pyo3-async-runtimes = { version = "0.23", features = ["attributes", "async-std-runtime"] }
5959
async-std = "1.13"
6060
```
6161

@@ -67,9 +67,9 @@ use pyo3::prelude::*;
6767
#[pyo3_async_runtimes::async_std::main]
6868
async fn main() -> PyResult<()> {
6969
let fut = Python::with_gil(|py| {
70-
let asyncio = py.import_bound("asyncio")?;
70+
let asyncio = py.import("asyncio")?;
7171
// convert asyncio.sleep into a Rust Future
72-
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
72+
pyo3_async_runtimes::async_std::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
7373
})?;
7474

7575
fut.await?;
@@ -84,8 +84,8 @@ attribute.
8484
```toml
8585
# Cargo.toml dependencies
8686
[dependencies]
87-
pyo3 = { version = "0.22" }
88-
pyo3-async-runtimes = { version = "0.22", features = ["attributes", "tokio-runtime"] }
87+
pyo3 = { version = "0.23" }
88+
pyo3-async-runtimes = { version = "0.23", features = ["attributes", "tokio-runtime"] }
8989
tokio = "1.40"
9090
```
9191

@@ -97,9 +97,9 @@ use pyo3::prelude::*;
9797
#[pyo3_async_runtimes::tokio::main]
9898
async fn main() -> PyResult<()> {
9999
let fut = Python::with_gil(|py| {
100-
let asyncio = py.import_bound("asyncio")?;
100+
let asyncio = py.import("asyncio")?;
101101
// convert asyncio.sleep into a Rust Future
102-
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
102+
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?)
103103
})?;
104104

105105
fut.await?;
@@ -130,8 +130,8 @@ For `async-std`:
130130

131131
```toml
132132
[dependencies]
133-
pyo3 = { version = "0.22", features = ["extension-module"] }
134-
pyo3-async-runtimes = { version = "0.22", features = ["async-std-runtime"] }
133+
pyo3 = { version = "0.23", features = ["extension-module"] }
134+
pyo3-async-runtimes = { version = "0.23", features = ["async-std-runtime"] }
135135
async-std = "1.13"
136136
```
137137

@@ -140,7 +140,7 @@ For `tokio`:
140140
```toml
141141
[dependencies]
142142
pyo3 = { version = "0.20", features = ["extension-module"] }
143-
pyo3-async-runtimes = { version = "0.22", features = ["tokio-runtime"] }
143+
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime"] }
144144
tokio = "1.40"
145145
```
146146

@@ -240,7 +240,7 @@ use pyo3::prelude::*;
240240
async fn main() -> PyResult<()> {
241241
let future = Python::with_gil(|py| -> PyResult<_> {
242242
// import the module containing the py_sleep function
243-
let example = py.import_bound("example")?;
243+
let example = py.import("example")?;
244244

245245
// calling the py_sleep method like a normal function
246246
// returns a coroutine
@@ -359,11 +359,11 @@ async fn main() -> PyResult<()> {
359359
// PyO3 is initialized - Ready to go
360360
361361
let fut = Python::with_gil(|py| -> PyResult<_> {
362-
let asyncio = py.import_bound("asyncio")?;
362+
let asyncio = py.import("asyncio")?;
363363
364364
// convert asyncio.sleep into a Rust Future
365365
pyo3_async_runtimes::async_std::into_future(
366-
asyncio.call_method1("sleep", (1.into_py(py),))?
366+
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?
367367
)
368368
})?;
369369
@@ -434,8 +434,8 @@ name = "my_async_module"
434434
crate-type = ["cdylib"]
435435

436436
[dependencies]
437-
pyo3 = { version = "0.22", features = ["extension-module"] }
438-
pyo3-async-runtimes = { version = "0.22", features = ["tokio-runtime"] }
437+
pyo3 = { version = "0.23", features = ["extension-module"] }
438+
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime"] }
439439
async-std = "1.13"
440440
tokio = "1.40"
441441
```
@@ -494,8 +494,8 @@ event loop before we can install the `uvloop` policy.
494494
```toml
495495
[dependencies]
496496
async-std = "1.13"
497-
pyo3 = "0.22"
498-
pyo3-async-runtimes = { version = "0.22", features = ["async-std-runtime"] }
497+
pyo3 = "0.23"
498+
pyo3-async-runtimes = { version = "0.23", features = ["async-std-runtime"] }
499499
```
500500

501501
```rust no_run
@@ -507,7 +507,7 @@ fn main() -> PyResult<()> {
507507
pyo3::prepare_freethreaded_python();
508508

509509
Python::with_gil(|py| {
510-
let uvloop = py.import_bound("uvloop")?;
510+
let uvloop = py.import("uvloop")?;
511511
uvloop.call_method0("install")?;
512512

513513
// store a reference for the assertion
@@ -604,7 +604,7 @@ To make things a bit easier, I decided to keep most of the old API alongside the
604604
pyo3::prepare_freethreaded_python();
605605

606606
Python::with_gil(|py| {
607-
let asyncio = py.import_bound("asyncio")?;
607+
let asyncio = py.import("asyncio")?;
608608

609609
let event_loop = asyncio.call_method0("new_event_loop")?;
610610
asyncio.call_method1("set_event_loop", (&event_loop,))?;

examples/async_std.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use pyo3::prelude::*;
33
#[pyo3_async_runtimes::async_std::main]
44
async fn main() -> PyResult<()> {
55
let fut = Python::with_gil(|py| {
6-
let asyncio = py.import_bound("asyncio")?;
6+
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
99
pyo3_async_runtimes::async_std::into_future(
10-
asyncio.call_method1("sleep", (1.into_py(py),))?,
10+
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
1111
)
1212
})?;
1313

examples/tokio.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ use pyo3::prelude::*;
33
#[pyo3_async_runtimes::tokio::main]
44
async fn main() -> PyResult<()> {
55
let fut = Python::with_gil(|py| {
6-
let asyncio = py.import_bound("asyncio")?;
6+
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
9+
pyo3_async_runtimes::tokio::into_future(
10+
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11+
)
1012
})?;
1113

1214
println!("sleeping for 1s");

examples/tokio_current_thread.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ use pyo3::prelude::*;
33
#[pyo3_async_runtimes::tokio::main(flavor = "current_thread")]
44
async fn main() -> PyResult<()> {
55
let fut = Python::with_gil(|py| {
6-
let asyncio = py.import_bound("asyncio")?;
6+
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
9+
pyo3_async_runtimes::tokio::into_future(
10+
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11+
)
1012
})?;
1113

1214
println!("sleeping for 1s");

examples/tokio_multi_thread.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ use pyo3::prelude::*;
33
#[pyo3_async_runtimes::tokio::main(flavor = "multi_thread", worker_threads = 10)]
44
async fn main() -> PyResult<()> {
55
let fut = Python::with_gil(|py| {
6-
let asyncio = py.import_bound("asyncio")?;
6+
let asyncio = py.import("asyncio")?;
77

88
// convert asyncio.sleep into a Rust Future
9-
pyo3_async_runtimes::tokio::into_future(asyncio.call_method1("sleep", (1.into_py(py),))?)
9+
pyo3_async_runtimes::tokio::into_future(
10+
asyncio.call_method1("sleep", (1.into_pyobject(py).unwrap(),))?,
11+
)
1012
})?;
1113

1214
println!("sleeping for 1s");

pyo3-async-runtimes-macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pyo3-async-runtimes-macros"
33
description = "Proc Macro Attributes for `pyo3-async-runtimes`"
4-
version = "0.22.0"
4+
version = "0.23.0"
55
authors = [
66
"Andrew J Westlake <[email protected]>",
77
"David Hewitt <[email protected]>",

pytests/common/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use std::ffi::CString;
12
use std::{thread, time::Duration};
23

34
use pyo3::prelude::*;
45
use pyo3_async_runtimes::TaskLocals;
56

6-
pub(super) const TEST_MOD: &'static str = r#"
7+
pub(super) const TEST_MOD: &str = r#"
78
import asyncio
89
910
async def py_sleep(duration):
@@ -15,12 +16,16 @@ async def sleep_for_1s(sleep_for):
1516

1617
pub(super) async fn test_into_future(event_loop: PyObject) -> PyResult<()> {
1718
let fut = Python::with_gil(|py| {
18-
let test_mod =
19-
PyModule::from_code_bound(py, TEST_MOD, "test_rust_coroutine/test_mod.py", "test_mod")?;
19+
let test_mod = PyModule::from_code(
20+
py,
21+
&CString::new(TEST_MOD).unwrap(),
22+
&CString::new("test_rust_coroutine/test_mod.py").unwrap(),
23+
&CString::new("test_mod").unwrap(),
24+
)?;
2025

2126
pyo3_async_runtimes::into_future_with_locals(
2227
&TaskLocals::new(event_loop.into_bound(py)),
23-
test_mod.call_method1("py_sleep", (1.into_py(py),))?,
28+
test_mod.call_method1("py_sleep", (1.into_pyobject(py).unwrap(),))?,
2429
)
2530
})?;
2631

@@ -36,8 +41,8 @@ pub(super) fn test_blocking_sleep() -> PyResult<()> {
3641

3742
pub(super) async fn test_other_awaitables(event_loop: PyObject) -> PyResult<()> {
3843
let fut = Python::with_gil(|py| {
39-
let functools = py.import_bound("functools")?;
40-
let time = py.import_bound("time")?;
44+
let functools = py.import("functools")?;
45+
let time = py.import("time")?;
4146

4247
// spawn a blocking sleep in the threadpool executor - returns a task, not a coroutine
4348
let task = event_loop.bind(py).call_method1(

0 commit comments

Comments
 (0)