Skip to content

Commit 2db5c97

Browse files
author
Andrew J Westlake
committed
Made macros use re-exports instead of relying on external dependencies
1 parent f9d093e commit 2db5c97

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

pyo3-asyncio-macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn async_std_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
146146
#body
147147
}
148148

149-
Box::pin(async_std::task::spawn_blocking(move || {
149+
Box::pin(pyo3_asyncio::async_std::spawn_blocking(move || {
150150
#name()
151151
}))
152152
}

pyo3-asyncio-macros/src/tokio.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ fn parse_knobs(
221221

222222
let mut rt = match config.flavor {
223223
RuntimeFlavor::CurrentThread => quote! {
224-
tokio::runtime::Builder::new_current_thread()
224+
pyo3_asyncio::tokio::runtime::Builder::new_current_thread()
225225
},
226226
RuntimeFlavor::Threaded => quote! {
227-
tokio::runtime::Builder::new_multi_thread()
227+
pyo3_asyncio::tokio::runtime::Builder::new_multi_thread()
228228
},
229229
};
230230
if let Some(v) = config.worker_threads {
@@ -234,7 +234,7 @@ fn parse_knobs(
234234
let rt_init = match config.flavor {
235235
RuntimeFlavor::CurrentThread => quote! {
236236
std::thread::spawn(|| pyo3_asyncio::tokio::get_runtime().block_on(
237-
std::future::pending::<()>()
237+
pyo3_asyncio::tokio::pending::<()>()
238238
));
239239
},
240240
_ => quote! {},

src/async_std.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use pyo3::prelude::*;
55

66
use crate::generic::{self, JoinError, Runtime};
77

8+
/// re-export spawn_blocking for use in `#[test]` macro without external dependency
9+
pub use async_std::task::spawn_blocking;
10+
811
/// <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>attributes</code></span> Provides the boilerplate for the `async-std` runtime and runs an async fn as main
912
#[cfg(feature = "attributes")]
1013
pub use pyo3_asyncio_macros::async_std_main as main;

src/tokio.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ use ::tokio::{
44
runtime::{Builder, Runtime},
55
task,
66
};
7-
use futures::future::pending;
87
use once_cell::sync::OnceCell;
98
use pyo3::prelude::*;
109

1110
use crate::generic;
1211

12+
/// re-export pending to be used in tokio macros without additional dependency
13+
pub use futures::future::pending;
14+
/// re-export tokio::runtime to build runtimes in tokio macros without additional dependency
15+
pub use tokio::runtime;
16+
1317
/// <span class="module-item stab portability" style="display: inline; border-radius: 3px; padding: 2px; font-size: 80%; line-height: 1.2;"><code>attributes</code></span>
1418
#[cfg(feature = "attributes")]
1519
pub use pyo3_asyncio_macros::tokio_main as main;

0 commit comments

Comments
 (0)