Skip to content

Commit 1289ad4

Browse files
Don't depend on the whole futures crate (#72)
Instead use futures-util/futures-channel Co-authored-by: David Hewitt <[email protected]>
1 parent f17e3b0 commit 1289ad4

File tree

11 files changed

+48
-44
lines changed

11 files changed

+48
-44
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async-std-runtime = ["async-std"]
2727
attributes = ["pyo3-async-runtimes-macros"]
2828
testing = ["clap", "inventory"]
2929
tokio-runtime = ["tokio"]
30-
unstable-streams = ["async-channel"]
30+
unstable-streams = ["async-channel", "futures-util/sink", "futures-channel/sink"]
3131
default = []
3232

3333
[package.metadata.docs.rs]
@@ -118,7 +118,8 @@ required-features = ["async-std-runtime", "testing"]
118118
[dependencies]
119119
async-channel = { version = "2.3", optional = true }
120120
clap = { version = "4.5", optional = true }
121-
futures = "0.3"
121+
futures-channel = "0.3"
122+
futures-util = "0.3"
122123
inventory = { version = "0.3", optional = true }
123124
once_cell = "1.14"
124125
pin-project-lite = "0.2"

pytests/test_async_std_asyncio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use pyo3::{
1616
use pyo3_async_runtimes::TaskLocals;
1717

1818
#[cfg(feature = "unstable-streams")]
19-
use futures::{StreamExt, TryStreamExt};
19+
use futures_util::stream::{StreamExt, TryStreamExt};
2020

2121
#[pyfunction]
2222
fn sleep<'p>(py: Python<'p>, secs: Bound<'p, PyAny>) -> PyResult<Bound<'p, PyAny>> {

pytests/test_tokio_current_thread_asyncio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ fn main() -> pyo3::PyResult<()> {
1212

1313
pyo3_async_runtimes::tokio::init(builder);
1414
std::thread::spawn(move || {
15-
pyo3_async_runtimes::tokio::get_runtime().block_on(futures::future::pending::<()>());
15+
pyo3_async_runtimes::tokio::get_runtime()
16+
.block_on(futures_util::future::pending::<()>());
1617
});
1718

1819
pyo3_async_runtimes::tokio::run(py, pyo3_async_runtimes::testing::main())

pytests/test_tokio_current_thread_run_forever.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010

1111
pyo3_async_runtimes::tokio::init(builder);
1212
std::thread::spawn(move || {
13-
pyo3_async_runtimes::tokio::get_runtime().block_on(futures::future::pending::<()>());
13+
pyo3_async_runtimes::tokio::get_runtime().block_on(futures_util::future::pending::<()>());
1414
});
1515

1616
tokio_run_forever::test_main();

pytests/test_tokio_current_thread_uvloop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() -> pyo3::PyResult<()> {
99

1010
pyo3_async_runtimes::tokio::init(builder);
1111
std::thread::spawn(move || {
12-
pyo3_async_runtimes::tokio::get_runtime().block_on(futures::future::pending::<()>());
12+
pyo3_async_runtimes::tokio::get_runtime().block_on(futures_util::future::pending::<()>());
1313
});
1414

1515
Python::attach(|py| {

pytests/tokio_asyncio/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use pyo3::{
1313
use pyo3_async_runtimes::TaskLocals;
1414

1515
#[cfg(feature = "unstable-streams")]
16-
use futures::{StreamExt, TryStreamExt};
16+
use futures_util::{StreamExt, TryStreamExt};
1717

1818
use crate::common;
1919

src/async_std.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! ```
1616
1717
use async_std::task;
18-
use futures::FutureExt;
18+
use futures_util::future::FutureExt;
1919
use pyo3::prelude::*;
2020
use std::{any::Any, cell::RefCell, future::Future, panic, panic::AssertUnwindSafe, pin::Pin};
2121

@@ -481,8 +481,8 @@ where
481481
///
482482
/// This function converts the `awaitable` into a Python Task using `run_coroutine_threadsafe`. A
483483
/// completion handler sends the result of this Task through a
484-
/// `futures::channel::oneshot::Sender<PyResult<Py<PyAny>>>` and the future returned by this function
485-
/// simply awaits the result through the `futures::channel::oneshot::Receiver<PyResult<Py<PyAny>>>`.
484+
/// `futures_channel::oneshot::Sender<PyResult<Py<PyAny>>>` and the future returned by this function
485+
/// simply awaits the result through the `futures_channel::oneshot::Receiver<PyResult<Py<PyAny>>>`.
486486
///
487487
/// # Arguments
488488
/// * `awaitable` - The Python `awaitable` to be converted
@@ -544,7 +544,7 @@ pub fn into_future(
544544
/// # Examples
545545
/// ```
546546
/// use pyo3::prelude::*;
547-
/// use futures::{StreamExt, TryStreamExt};
547+
/// use futures_util::stream::{StreamExt, TryStreamExt};
548548
/// use std::ffi::CString;
549549
///
550550
/// const TEST_MOD: &str = r#"
@@ -585,7 +585,7 @@ pub fn into_future(
585585
#[cfg(feature = "unstable-streams")]
586586
pub fn into_stream_v1(
587587
gen: Bound<'_, PyAny>,
588-
) -> PyResult<impl futures::Stream<Item = PyResult<Py<PyAny>>> + 'static> {
588+
) -> PyResult<impl futures_util::stream::Stream<Item = PyResult<Py<PyAny>>> + 'static> {
589589
generic::into_stream_v1::<AsyncStdRuntime>(gen)
590590
}
591591

@@ -602,7 +602,7 @@ pub fn into_stream_v1(
602602
/// # Examples
603603
/// ```
604604
/// use pyo3::prelude::*;
605-
/// use futures::{StreamExt, TryStreamExt};
605+
/// use futures_util::stream::{StreamExt, TryStreamExt};
606606
/// use std::ffi::CString;
607607
///
608608
/// const TEST_MOD: &str = r#"
@@ -647,7 +647,7 @@ pub fn into_stream_v1(
647647
pub fn into_stream_with_locals_v1(
648648
locals: TaskLocals,
649649
gen: Bound<'_, PyAny>,
650-
) -> PyResult<impl futures::Stream<Item = PyResult<Py<PyAny>>> + 'static> {
650+
) -> PyResult<impl futures_util::stream::Stream<Item = PyResult<Py<PyAny>>> + 'static> {
651651
generic::into_stream_with_locals_v1::<AsyncStdRuntime>(locals, gen)
652652
}
653653

@@ -664,7 +664,7 @@ pub fn into_stream_with_locals_v1(
664664
/// # Examples
665665
/// ```
666666
/// use pyo3::prelude::*;
667-
/// use futures::{StreamExt, TryStreamExt};
667+
/// use futures_util::stream::{StreamExt, TryStreamExt};
668668
/// use std::ffi::CString;
669669
///
670670
/// const TEST_MOD: &str = r#"
@@ -709,7 +709,7 @@ pub fn into_stream_with_locals_v1(
709709
pub fn into_stream_with_locals_v2(
710710
locals: TaskLocals,
711711
gen: Bound<'_, PyAny>,
712-
) -> PyResult<impl futures::Stream<Item = Py<PyAny>> + 'static> {
712+
) -> PyResult<impl futures_util::stream::Stream<Item = Py<PyAny>> + 'static> {
713713
generic::into_stream_with_locals_v2::<AsyncStdRuntime>(locals, gen)
714714
}
715715

@@ -725,7 +725,7 @@ pub fn into_stream_with_locals_v2(
725725
/// # Examples
726726
/// ```
727727
/// use pyo3::prelude::*;
728-
/// use futures::{StreamExt, TryStreamExt};
728+
/// use futures_util::stream::{StreamExt, TryStreamExt};
729729
/// use std::ffi::CString;
730730
///
731731
/// const TEST_MOD: &str = r#"
@@ -766,6 +766,6 @@ pub fn into_stream_with_locals_v2(
766766
#[cfg(feature = "unstable-streams")]
767767
pub fn into_stream_v2(
768768
gen: Bound<'_, PyAny>,
769-
) -> PyResult<impl futures::Stream<Item = Py<PyAny>> + 'static> {
769+
) -> PyResult<impl futures_util::stream::Stream<Item = Py<PyAny>> + 'static> {
770770
generic::into_stream_v2::<AsyncStdRuntime>(gen)
771771
}

src/generic.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ use crate::{
2424
asyncio, call_soon_threadsafe, close, create_future, dump_err, err::RustPanic,
2525
get_running_loop, into_future_with_locals, TaskLocals,
2626
};
27-
use futures::channel::oneshot;
2827
#[cfg(feature = "unstable-streams")]
29-
use futures::{channel::mpsc, SinkExt};
28+
use futures_channel::mpsc;
29+
use futures_channel::oneshot;
30+
#[cfg(feature = "unstable-streams")]
31+
use futures_util::SinkExt;
3032
use pin_project_lite::pin_project;
3133
use pyo3::prelude::*;
3234
use pyo3::IntoPyObjectExt;
@@ -1307,7 +1309,7 @@ where
13071309
/// # }
13081310
///
13091311
/// use pyo3::prelude::*;
1310-
/// use futures::{StreamExt, TryStreamExt};
1312+
/// use futures_util::stream::{StreamExt, TryStreamExt};
13111313
/// use std::ffi::CString;
13121314
///
13131315
/// const TEST_MOD: &str = r#"
@@ -1349,7 +1351,7 @@ where
13491351
pub fn into_stream_with_locals_v1<R>(
13501352
locals: TaskLocals,
13511353
gen: Bound<'_, PyAny>,
1352-
) -> PyResult<impl futures::Stream<Item = PyResult<Py<PyAny>>> + 'static>
1354+
) -> PyResult<impl futures_util::stream::Stream<Item = PyResult<Py<PyAny>>> + 'static>
13531355
where
13541356
R: Runtime,
13551357
{
@@ -1461,7 +1463,7 @@ where
14611463
/// # }
14621464
///
14631465
/// use pyo3::prelude::*;
1464-
/// use futures::{StreamExt, TryStreamExt};
1466+
/// use futures_util::stream::{StreamExt, TryStreamExt};
14651467
/// use std::ffi::CString;
14661468
///
14671469
/// const TEST_MOD: &str = r#"
@@ -1498,7 +1500,7 @@ where
14981500
#[cfg(feature = "unstable-streams")]
14991501
pub fn into_stream_v1<R>(
15001502
gen: Bound<'_, PyAny>,
1501-
) -> PyResult<impl futures::Stream<Item = PyResult<Py<PyAny>>> + 'static>
1503+
) -> PyResult<impl futures_util::stream::Stream<Item = PyResult<Py<PyAny>>> + 'static>
15021504
where
15031505
R: Runtime + ContextExt,
15041506
{
@@ -1660,7 +1662,7 @@ async def forward(gen, sender):
16601662
/// # }
16611663
///
16621664
/// use pyo3::prelude::*;
1663-
/// use futures::{StreamExt, TryStreamExt};
1665+
/// use futures_util::stream::{StreamExt, TryStreamExt};
16641666
/// use std::ffi::CString;
16651667
///
16661668
/// const TEST_MOD: &str = r#"
@@ -1701,7 +1703,7 @@ async def forward(gen, sender):
17011703
pub fn into_stream_with_locals_v2<R>(
17021704
locals: TaskLocals,
17031705
gen: Bound<'_, PyAny>,
1704-
) -> PyResult<impl futures::Stream<Item = Py<PyAny>> + 'static>
1706+
) -> PyResult<impl futures_util::stream::Stream<Item = Py<PyAny>> + 'static>
17051707
where
17061708
R: Runtime + ContextExt,
17071709
{
@@ -1819,7 +1821,7 @@ where
18191821
/// # }
18201822
///
18211823
/// use pyo3::prelude::*;
1822-
/// use futures::{StreamExt, TryStreamExt};
1824+
/// use futures_util::stream::{StreamExt, TryStreamExt};
18231825
/// use std::ffi::CString;
18241826
///
18251827
/// const TEST_MOD: &str = r#"
@@ -1856,7 +1858,7 @@ where
18561858
#[cfg(feature = "unstable-streams")]
18571859
pub fn into_stream_v2<R>(
18581860
gen: Bound<'_, PyAny>,
1859-
) -> PyResult<impl futures::Stream<Item = Py<PyAny>> + 'static>
1861+
) -> PyResult<impl futures_util::stream::Stream<Item = Py<PyAny>> + 'static>
18601862
where
18611863
R: Runtime + ContextExt,
18621864
{

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ pub mod doc_test {
397397
use std::future::Future;
398398
use std::sync::Arc;
399399

400-
use futures::channel::oneshot;
400+
use futures_channel::oneshot;
401401
use pyo3::{call::PyCallArgs, prelude::*, sync::PyOnceLock, types::PyDict};
402402

403403
static ASYNCIO: PyOnceLock<Py<PyAny>> = PyOnceLock::new();
@@ -610,8 +610,8 @@ fn call_soon_threadsafe<'py>(
610610
///
611611
/// This function converts the `awaitable` into a Python Task using `run_coroutine_threadsafe`. A
612612
/// completion handler sends the result of this Task through a
613-
/// `futures::channel::oneshot::Sender<PyResult<Py<PyAny>>>` and the future returned by this function
614-
/// simply awaits the result through the `futures::channel::oneshot::Receiver<PyResult<Py<PyAny>>>`.
613+
/// `futures_channel::oneshot::Sender<PyResult<Py<PyAny>>>` and the future returned by this function
614+
/// simply awaits the result through the `futures_channel::oneshot::Receiver<PyResult<Py<PyAny>>>`.
615615
///
616616
/// # Arguments
617617
/// * `locals` - The Python event loop and context to be used for the provided awaitable

src/testing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
use std::{future::Future, pin::Pin};
183183

184184
use clap::{Arg, Command};
185-
use futures::stream::{self, StreamExt};
185+
use futures_util::stream::StreamExt;
186186
use pyo3::prelude::*;
187187

188188
/// Args that should be provided to the test program
@@ -263,7 +263,7 @@ inventory::collect!(Test);
263263

264264
/// Run a sequence of tests while applying any necessary filtering from the `Args`
265265
pub async fn test_harness(tests: Vec<Test>, args: Args) -> PyResult<()> {
266-
stream::iter(tests)
266+
futures_util::stream::iter(tests)
267267
.for_each_concurrent(Some(4), |test| {
268268
let mut ignore = false;
269269

0 commit comments

Comments
 (0)