← back to Exo
remove dead code (#1496)
8f01523ddbf86155e88cc25907690f1ddf416825 · 2026-02-18 11:43:27 +0000 · Evan Quiney
Files touched
M Cargo.lockM Cargo.tomlM rust/exo_pyo3_bindings/Cargo.tomlM rust/exo_pyo3_bindings/src/allow_threading.rsD rust/exo_pyo3_bindings/src/examples/mod.rsM rust/exo_pyo3_bindings/src/lib.rsM rust/exo_pyo3_bindings/src/networking.rsM rust/networking/Cargo.tomlM rust/networking/examples/chatroom_manual.rsM rust/networking/src/discovery.rsD rust/networking/src/keep_alive.rsM rust/networking/src/lib.rs
Diff
commit 8f01523ddbf86155e88cc25907690f1ddf416825
Author: Evan Quiney <evanev7@gmail.com>
Date: Wed Feb 18 11:43:27 2026 +0000
remove dead code (#1496)
---
Cargo.lock | 123 -------------
Cargo.toml | 28 ---
rust/exo_pyo3_bindings/Cargo.toml | 25 +--
rust/exo_pyo3_bindings/src/allow_threading.rs | 6 +-
rust/exo_pyo3_bindings/src/examples/mod.rs | 240 --------------------------
rust/exo_pyo3_bindings/src/lib.rs | 29 +---
rust/exo_pyo3_bindings/src/networking.rs | 7 +-
rust/networking/Cargo.toml | 9 +-
rust/networking/examples/chatroom_manual.rs | 2 +-
rust/networking/src/discovery.rs | 1 -
rust/networking/src/keep_alive.rs | 44 -----
rust/networking/src/lib.rs | 20 ---
12 files changed, 14 insertions(+), 520 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index a45bfe9d..089f5b65 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -141,12 +141,6 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
-[[package]]
-name = "arrayvec"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
-
[[package]]
name = "asn1-rs"
version = "0.7.1"
@@ -304,19 +298,6 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba"
-[[package]]
-name = "bigdecimal"
-version = "0.4.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "560f42649de9fa436b73517378a147ec21f6c997a546581df4b4b31677828934"
-dependencies = [
- "autocfg",
- "libm",
- "num-bigint",
- "num-integer",
- "num-traits",
-]
-
[[package]]
name = "bimap"
version = "0.6.3"
@@ -516,15 +497,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f421161cb492475f1661ddc9815a745a1c894592070661180fdec3d4872e9c3"
-[[package]]
-name = "convert_case"
-version = "0.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9"
-dependencies = [
- "unicode-segmentation",
-]
-
[[package]]
name = "core-foundation"
version = "0.9.4"
@@ -746,29 +718,6 @@ dependencies = [
"powerfmt",
]
-[[package]]
-name = "derive_more"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10b768e943bed7bf2cab53df09f4bc34bfd217cdb57d971e769874c9a6710618"
-dependencies = [
- "derive_more-impl",
-]
-
-[[package]]
-name = "derive_more-impl"
-version = "2.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d286bfdaf75e988b4a78e013ecd79c581e06399ab53fbacd2d916c2f904f30b"
-dependencies = [
- "convert_case",
- "proc-macro2",
- "quote",
- "rustc_version",
- "syn 2.0.111",
- "unicode-xid",
-]
-
[[package]]
name = "digest"
version = "0.10.7"
@@ -939,22 +888,17 @@ name = "exo_pyo3_bindings"
version = "0.0.1"
dependencies = [
"delegate",
- "derive_more",
"env_logger",
"extend",
"futures",
- "impl-trait-for-tuples",
"libp2p",
"log",
"networking",
- "once_cell",
"pin-project",
"pyo3",
"pyo3-async-runtimes",
"pyo3-log",
"pyo3-stub-gen",
- "thiserror 2.0.17",
- "thread_local",
"tokio",
"util",
]
@@ -1640,17 +1584,6 @@ dependencies = [
"xmltree",
]
-[[package]]
-name = "impl-trait-for-tuples"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.111",
-]
-
[[package]]
name = "indexmap"
version = "2.12.1"
@@ -1829,12 +1762,6 @@ version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
-[[package]]
-name = "libm"
-version = "0.2.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
-
[[package]]
name = "libp2p"
version = "0.56.0"
@@ -2824,16 +2751,13 @@ name = "networking"
version = "0.0.1"
dependencies = [
"delegate",
- "derive_more",
"either",
"extend",
"futures",
"futures-timer",
- "impl-trait-for-tuples",
"keccak-const",
"libp2p",
"log",
- "thiserror 2.0.17",
"tokio",
"tracing-subscriber",
"util",
@@ -2918,17 +2842,6 @@ dependencies = [
"num-traits",
]
-[[package]]
-name = "num-rational"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
-dependencies = [
- "num-bigint",
- "num-integer",
- "num-traits",
-]
-
[[package]]
name = "num-traits"
version = "0.2.19"
@@ -3279,28 +3192,14 @@ version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d"
dependencies = [
- "bigdecimal",
- "either",
- "hashbrown 0.16.1",
- "indexmap",
"indoc",
- "inventory",
"libc",
- "lock_api",
"memoffset",
- "num-bigint",
- "num-complex",
- "num-rational",
- "num-traits",
"once_cell",
- "ordered-float",
- "parking_lot",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
- "rust_decimal",
- "smallvec",
"unindent",
]
@@ -3741,16 +3640,6 @@ dependencies = [
"tokio",
]
-[[package]]
-name = "rust_decimal"
-version = "1.39.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35affe401787a9bd846712274d97654355d21b2a2c092a3139aabe31e9022282"
-dependencies = [
- "arrayvec",
- "num-traits",
-]
-
[[package]]
name = "rustc-hash"
version = "1.1.0"
@@ -4615,24 +4504,12 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
-[[package]]
-name = "unicode-segmentation"
-version = "1.12.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
-
[[package]]
name = "unicode-width"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
-[[package]]
-name = "unicode-xid"
-version = "0.2.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
-
[[package]]
name = "unicode_names2"
version = "1.3.0"
diff --git a/Cargo.toml b/Cargo.toml
index 34339ede..4c0b8721 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,49 +26,21 @@ opt-level = 3
networking = { path = "rust/networking" }
util = { path = "rust/util" }
-# Proc-macro authoring tools
-syn = "2.0"
-quote = "1.0"
-proc-macro2 = "1.0"
-darling = "0.20"
-
# Macro dependecies
extend = "1.2"
delegate = "0.13"
-impl-trait-for-tuples = "0.2"
-clap = "4.5"
-derive_more = { version = "2.0.1", features = ["display"] }
pin-project = "1"
# Utility dependencies
-itertools = "0.14"
-thiserror = "2"
-internment = "0.8"
-recursion = "0.5"
-regex = "1.11"
-once_cell = "1.21"
-thread_local = "1.1"
-bon = "3.4"
-generativity = "1.1"
-anyhow = "1.0"
keccak-const = "0.2"
-# Functional generics/lenses frameworks
-frunk_core = "0.4"
-frunk = "0.4"
-frunk_utils = "0.2"
-frunk-enum-core = "0.3"
-
# Async dependencies
tokio = "1.46"
futures = "0.3"
-futures-util = "0.3"
futures-timer = "3.0"
# Data structures
either = "1.15"
-ordered-float = "5.0"
-ahash = "0.8"
# Tracing/logging
log = "0.4"
diff --git a/rust/exo_pyo3_bindings/Cargo.toml b/rust/exo_pyo3_bindings/Cargo.toml
index 12803ab4..e97b9148 100644
--- a/rust/exo_pyo3_bindings/Cargo.toml
+++ b/rust/exo_pyo3_bindings/Cargo.toml
@@ -25,17 +25,17 @@ workspace = true
networking = { workspace = true }
# interop
-pyo3 = { version = "0.27.1", features = [
- # "abi3-py311", # tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.11
+pyo3 = { version = "0.27.2", features = [
+ # "abi3-py313", # tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.13
"nightly", # enables better-supported GIL integration
"experimental-async", # async support in #[pyfunction] & #[pymethods]
#"experimental-inspect", # inspection of generated binary => easier to automate type-hint generation
#"py-clone", # adding Clone-ing of `Py<T>` without GIL (may cause panics - remove if panics happen)
- "multiple-pymethods", # allows multiple #[pymethods] sections per class
+ # "multiple-pymethods", # allows multiple #[pymethods] sections per class
# integrations with other libraries
- "arc_lock", "bigdecimal", "either", "hashbrown", "indexmap", "num-bigint", "num-complex", "num-rational",
- "ordered-float", "rust_decimal", "smallvec",
+ # "arc_lock", "bigdecimal", "either", "hashbrown", "indexmap", "num-bigint", "num-complex", "num-rational",
+ # "ordered-float", "rust_decimal", "smallvec",
# "anyhow", "chrono", "chrono-local", "chrono-tz", "eyre", "jiff-02", "lock_api", "parking-lot", "time", "serde",
] }
pyo3-stub-gen = { version = "0.17.2" }
@@ -45,8 +45,6 @@ pyo3-log = "0.13.2"
# macro dependencies
extend = { workspace = true }
delegate = { workspace = true }
-impl-trait-for-tuples = { workspace = true }
-derive_more = { workspace = true }
pin-project = { workspace = true }
# async runtime
@@ -54,24 +52,11 @@ tokio = { workspace = true, features = ["full", "tracing"] }
futures = { workspace = true }
# utility dependencies
-once_cell = "1.21.3"
-thread_local = "1.1.9"
util = { workspace = true }
-thiserror = { workspace = true }
-#internment = { workspace = true }
-#recursion = { workspace = true }
-#generativity = { workspace = true }
-#itertools = { workspace = true }
-
# Tracing
-#tracing = "0.1"
-#tracing-subscriber = "0.3"
-#console-subscriber = "0.1.5"
-#tracing-log = "0.2.0"
log = { workspace = true }
env_logger = "0.11"
-
# Networking
libp2p = { workspace = true, features = ["full"] }
diff --git a/rust/exo_pyo3_bindings/src/allow_threading.rs b/rust/exo_pyo3_bindings/src/allow_threading.rs
index 3106e535..18a426aa 100644
--- a/rust/exo_pyo3_bindings/src/allow_threading.rs
+++ b/rust/exo_pyo3_bindings/src/allow_threading.rs
@@ -6,7 +6,7 @@ use pyo3::marker::Ungil;
use pyo3::prelude::*;
use std::{
future::Future,
- pin::{Pin, pin},
+ pin::Pin,
task::{Context, Poll},
};
@@ -33,8 +33,6 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let waker = cx.waker();
- Python::with_gil(|py| {
- py.allow_threads(|| self.project().0.poll(&mut Context::from_waker(waker)))
- })
+ Python::attach(|py| py.detach(|| self.project().0.poll(&mut Context::from_waker(waker))))
}
}
diff --git a/rust/exo_pyo3_bindings/src/examples/mod.rs b/rust/exo_pyo3_bindings/src/examples/mod.rs
deleted file mode 100644
index bde14199..00000000
--- a/rust/exo_pyo3_bindings/src/examples/mod.rs
+++ /dev/null
@@ -1,240 +0,0 @@
-//! This module exists to hold examples of some pyo3 patterns that may be too complex to
-//! re-create from scratch, but too inhomogenous to create an abstraction/wrapper around.
-//!
-//! Pattern examples include:
-//! - Async task handles: with GC-integrated cleanup
-//! - Sync/async callbacks from python: with propper eventloop handling
-//!
-//! Mutability pattern: https://pyo3.rs/v0.26.0/async-await.html#send--static-constraint
-//! - Store mutable fields in tokio's `Mutex<T>`
-//! - For async code: take `&self` and `.lock().await`
-//! - For sync code: take `&mut self` and `.get_mut()`
-
-use crate::ext::{PyResultExt as _, ResultExt as _, TokioRuntimeExt as _};
-use futures::FutureExt as _;
-use futures::future::BoxFuture;
-use pyo3::exceptions::PyRuntimeError;
-use pyo3::prelude::{PyModule, PyModuleMethods as _};
-use pyo3::{
- Bound, Py, PyAny, PyErr, PyResult, PyTraverseError, PyVisit, Python, pyclass, pymethods,
-};
-use std::time::Duration;
-use tokio::sync::mpsc;
-use tokio::sync::mpsc::error::TryRecvError;
-
-fn needs_tokio_runtime() {
- tokio::runtime::Handle::current();
-}
-
-type SyncCallback = Box<dyn Fn() + Send + Sync>;
-type AsyncCallback = Box<dyn Fn() -> BoxFuture<'static, ()> + Send + Sync>;
-
-enum AsyncTaskMessage {
- SyncCallback(SyncCallback),
- AsyncCallback(AsyncCallback),
-}
-
-async fn async_task(
- sender: mpsc::UnboundedSender<()>,
- mut receiver: mpsc::UnboundedReceiver<AsyncTaskMessage>,
-) {
- log::info!("RUST: async task started");
-
- // task state
- let mut interval = tokio::time::interval(Duration::from_secs(1));
-
- let mut sync_cbs: Vec<SyncCallback> = vec![];
- let mut async_cbs: Vec<AsyncCallback> = vec![];
-
- loop {
- tokio::select! {
- // handle incoming messages from task-handle
- message = receiver.recv() => {
- // handle closed channel by exiting
- let Some(message) = message else {
- log::info!("RUST: channel closed");
- break;
- };
-
- // dispatch incoming event
- match message {
- AsyncTaskMessage::SyncCallback(cb) => {
- sync_cbs.push(cb);
- }
- AsyncTaskMessage::AsyncCallback(cb) => {
- async_cbs.push(cb);
- }
- }
- }
-
- // handle all other events
- _ = interval.tick() => {
- log::info!("RUST: async task tick");
-
- // call back all sync callbacks
- for cb in &sync_cbs {
- cb();
- }
-
- // call back all async callbacks
- for cb in &async_cbs {
- cb().await;
- }
-
- // send event on unbounded channel
- sender.send(()).expect("handle receiver cannot be closed/dropped");
- }
- }
- }
-
- log::info!("RUST: async task stopped");
-}
-
-// #[gen_stub_pyclass]
-#[pyclass(name = "AsyncTaskHandle")]
-#[derive(Debug)]
-struct PyAsyncTaskHandle {
- sender: Option<mpsc::UnboundedSender<AsyncTaskMessage>>,
- receiver: mpsc::UnboundedReceiver<()>,
-}
-
-#[allow(clippy::expect_used)]
-impl PyAsyncTaskHandle {
- const fn sender(&self) -> &mpsc::UnboundedSender<AsyncTaskMessage> {
- self.sender
- .as_ref()
- .expect("The sender should only be None after de-initialization.")
- }
-
- const fn sender_mut(&mut self) -> &mpsc::UnboundedSender<AsyncTaskMessage> {
- self.sender
- .as_mut()
- .expect("The sender should only be None after de-initialization.")
- }
-
- const fn new(
- sender: mpsc::UnboundedSender<AsyncTaskMessage>,
- receiver: mpsc::UnboundedReceiver<()>,
- ) -> Self {
- Self {
- sender: Some(sender),
- receiver,
- }
- }
-}
-
-// #[gen_stub_pymethods]
-#[pymethods]
-impl PyAsyncTaskHandle {
- #[new]
- fn py_new(py: Python<'_>) -> PyResult<Self> {
- use pyo3_async_runtimes::tokio::get_runtime;
-
- // create communication channel TOWARDS our task
- let (h_sender, t_receiver) = mpsc::unbounded_channel::<AsyncTaskMessage>();
-
- // create communication channel FROM our task
- let (t_sender, h_receiver) = mpsc::unbounded_channel::<()>();
-
- // perform necessary setup within tokio context - or it crashes
- let () = get_runtime().block_on(async { needs_tokio_runtime() });
-
- // spawn tokio task with this thread's task-locals - without this, async callbacks on the new threads will not work!!
- _ = get_runtime().spawn_with_scope(py, async move {
- async_task(t_sender, t_receiver).await;
- });
- Ok(Self::new(h_sender, h_receiver))
- }
-
- /// NOTE: exceptions in callbacks are silently ignored until end of execution
- fn add_sync_callback(
- &self,
- // #[gen_stub(override_type(
- // type_repr="collections.abc.Callable[[], None]",
- // imports=("collections.abc")
- // ))]
- callback: Py<PyAny>,
- ) -> PyResult<()> {
- // blocking call to async method -> can do non-blocking if needed
- self.sender()
- .send(AsyncTaskMessage::SyncCallback(Box::new(move || {
- _ = Python::with_gil(|py| callback.call0(py).write_unraisable_with(py));
- })))
- .pyerr()?;
- Ok(())
- }
-
- /// NOTE: exceptions in callbacks are silently ignored until end of execution
- fn add_async_callback(
- &self,
- // #[gen_stub(override_type(
- // type_repr="collections.abc.Callable[[], collections.abc.Awaitable[None]]",
- // imports=("collections.abc")
- // ))]
- callback: Py<PyAny>,
- ) -> PyResult<()> {
- // blocking call to async method -> can do non-blocking if needed
- self.sender()
- .send(AsyncTaskMessage::AsyncCallback(Box::new(move || {
- let c = Python::with_gil(|py| callback.clone_ref(py));
- async move {
- if let Some(f) = Python::with_gil(|py| {
- let coroutine = c.call0(py).write_unraisable_with(py)?;
- pyo3_async_runtimes::tokio::into_future(coroutine.into_bound(py))
- .write_unraisable_with(py)
- }) {
- _ = f.await.write_unraisable();
- }
- }
- .boxed()
- })))
- .pyerr()?;
- Ok(())
- }
-
- async fn receive_unit(&mut self) -> PyResult<()> {
- self.receiver
- .recv()
- .await
- .ok_or(PyErr::new::<PyRuntimeError, _>(
- "cannot receive unit on closed channel",
- ))
- }
-
- fn drain_units(&mut self) -> PyResult<i32> {
- let mut cnt = 0;
- loop {
- match self.receiver.try_recv() {
- Err(TryRecvError::Disconnected) => {
- return Err(PyErr::new::<PyRuntimeError, _>(
- "cannot receive unit on closed channel",
- ));
- }
- Err(TryRecvError::Empty) => return Ok(cnt),
- Ok(()) => {
- cnt += 1;
- continue;
- }
- }
- }
- }
-
- // #[gen_stub(skip)]
- const fn __traverse__(&self, _visit: PyVisit<'_>) -> Result<(), PyTraverseError> {
- Ok(()) // This is needed purely so `__clear__` can work
- }
-
- // #[gen_stub(skip)]
- fn __clear__(&mut self) {
- // TODO: may or may not need to await a "kill-signal" oneshot channel message,
- // to ensure that the networking task is done BEFORE exiting the clear function...
- // but this may require GIL?? and it may not be safe to call GIL here??
- self.sender = None; // Using Option<T> as a trick to force `sender` channel to be dropped
- }
-}
-
-pub fn examples_submodule(m: &Bound<'_, PyModule>) -> PyResult<()> {
- m.add_class::<PyAsyncTaskHandle>()?;
-
- Ok(())
-}
diff --git a/rust/exo_pyo3_bindings/src/lib.rs b/rust/exo_pyo3_bindings/src/lib.rs
index 4f591b8c..25f2865e 100644
--- a/rust/exo_pyo3_bindings/src/lib.rs
+++ b/rust/exo_pyo3_bindings/src/lib.rs
@@ -17,7 +17,6 @@
extern crate core;
mod allow_threading;
-mod examples;
pub(crate) mod networking;
pub(crate) mod pylibp2p;
@@ -25,7 +24,6 @@ use crate::networking::networking_submodule;
use crate::pylibp2p::ident::ident_submodule;
use crate::pylibp2p::multiaddr::multiaddr_submodule;
use pyo3::prelude::PyModule;
-use pyo3::prelude::*;
use pyo3::{Bound, PyResult, pyclass, pymodule};
use pyo3_stub_gen::define_stub_info_gatherer;
@@ -36,14 +34,10 @@ pub(crate) mod r#const {
/// Namespace for all the type/trait aliases used by this crate.
pub(crate) mod alias {
- use std::error::Error;
use std::marker::Tuple;
pub trait SendFn<Args: Tuple + Send + 'static, Output> =
Fn<Args, Output = Output> + Send + 'static;
-
- pub type AnyError = Box<dyn Error + Send + Sync + 'static>;
- pub type AnyResult<T> = Result<T, AnyError>;
}
/// Namespace for crate-wide extension traits/methods
@@ -51,7 +45,6 @@ pub(crate) mod ext {
use crate::allow_threading::AllowThreads;
use extend::ext;
use pyo3::exceptions::{PyConnectionError, PyRuntimeError};
- use pyo3::marker::Ungil;
use pyo3::types::PyBytes;
use pyo3::{Py, PyErr, PyResult, Python};
use tokio::runtime::Runtime;
@@ -62,7 +55,7 @@ pub(crate) mod ext {
#[ext(pub, name = ByteArrayExt)]
impl [u8] {
fn pybytes(&self) -> Py<PyBytes> {
- Python::with_gil(|py| PyBytes::new(py, self).unbind())
+ Python::attach(|py| PyBytes::new(py, self).unbind())
}
}
@@ -98,7 +91,7 @@ pub(crate) mod ext {
#[ext(pub, name = PyResultExt)]
impl<T> PyResult<T> {
fn write_unraisable(self) -> Option<T> {
- Python::with_gil(|py| self.write_unraisable_with(py))
+ Python::attach(|py| self.write_unraisable_with(py))
}
fn write_unraisable_with(self, py: Python<'_>) -> Option<T> {
@@ -175,24 +168,6 @@ pub(crate) mod ext {
}
}
-pub(crate) mod private {
- use std::marker::Sized;
-
- /// Sealed traits support
- pub trait Sealed {}
- impl<T: ?Sized> Sealed for T {}
-}
-
-/// A wrapper around [`Py`] that implements [`Clone`] using [`Python::with_gil`].
-#[repr(transparent)]
-pub(crate) struct ClonePy<T>(pub Py<T>);
-
-impl<T> Clone for ClonePy<T> {
- fn clone(&self) -> Self {
- Python::with_gil(|py| Self(self.0.clone_ref(py)))
- }
-}
-
/// A Python module implemented in Rust. The name of this function must match
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
/// import the module.
diff --git a/rust/exo_pyo3_bindings/src/networking.rs b/rust/exo_pyo3_bindings/src/networking.rs
index 01024cf9..03a0dcb6 100644
--- a/rust/exo_pyo3_bindings/src/networking.rs
+++ b/rust/exo_pyo3_bindings/src/networking.rs
@@ -11,9 +11,9 @@ use crate::ext::{ResultExt as _, TokioMpscReceiverExt as _, TokioMpscSenderExt a
use crate::pyclass;
use crate::pylibp2p::ident::{PyKeypair, PyPeerId};
use libp2p::futures::StreamExt as _;
+use libp2p::gossipsub;
use libp2p::gossipsub::{IdentTopic, Message, MessageId, PublishError};
use libp2p::swarm::SwarmEvent;
-use libp2p::{gossipsub, mdns};
use networking::discovery;
use networking::swarm::create_swarm;
use pyo3::prelude::{PyModule, PyModuleMethods as _};
@@ -25,7 +25,7 @@ use tokio::sync::{Mutex, mpsc, oneshot};
mod exception {
use pyo3::types::PyTuple;
- use pyo3::{PyErrArguments, exceptions::PyException, prelude::*};
+ use pyo3::{exceptions::PyException, prelude::*};
use pyo3_stub_gen::derive::*;
#[gen_stub_pyclass]
@@ -155,7 +155,6 @@ async fn networking_task(
) {
use SwarmEvent::*;
use ToTask::*;
- use mdns::Event::*;
use networking::swarm::BehaviourEvent::*;
log::info!("RUST: networking task started");
@@ -485,7 +484,7 @@ impl PyNetworkingHandle {
let (tx, rx) = oneshot::channel();
// send off request to subscribe
- let data = Python::with_gil(|py| Vec::from(data.as_bytes(py)));
+ let data = Python::attach(|py| Vec::from(data.as_bytes(py)));
self.to_task_tx()
.send_py(ToTask::GossipsubPublish {
topic,
diff --git a/rust/networking/Cargo.toml b/rust/networking/Cargo.toml
index 47d61f41..fd5f1b1f 100644
--- a/rust/networking/Cargo.toml
+++ b/rust/networking/Cargo.toml
@@ -19,8 +19,6 @@ either = { workspace = true }
# macro dependencies
extend = { workspace = true }
delegate = { workspace = true }
-impl-trait-for-tuples = { workspace = true }
-derive_more = { workspace = true }
# async
tokio = { workspace = true, features = ["full"] }
@@ -29,11 +27,6 @@ futures-timer = { workspace = true }
# utility dependencies
util = { workspace = true }
-thiserror = { workspace = true }
-#internment = { workspace = true }
-#recursion = { workspace = true }
-#generativity = { workspace = true }
-#itertools = { workspace = true }
tracing-subscriber = { version = "0.3.19", features = ["default", "env-filter"] }
keccak-const = { workspace = true }
@@ -41,4 +34,4 @@ keccak-const = { workspace = true }
log = { workspace = true }
# networking
-libp2p = { workspace = true, features = ["full"] }
\ No newline at end of file
+libp2p = { workspace = true, features = ["full"] }
diff --git a/rust/networking/examples/chatroom_manual.rs b/rust/networking/examples/chatroom_manual.rs
index 5d92ac86..e9f10a1f 100644
--- a/rust/networking/examples/chatroom_manual.rs
+++ b/rust/networking/examples/chatroom_manual.rs
@@ -24,8 +24,8 @@ use libp2p::{
swarm::{NetworkBehaviour, SwarmEvent},
tcp, yamux,
};
+use std::error::Error;
use std::time::Duration;
-use std::{error::Error, hash::Hash};
use tokio::{io, io::AsyncBufReadExt, select};
use tracing_subscriber::EnvFilter;
diff --git a/rust/networking/src/discovery.rs b/rust/networking/src/discovery.rs
index b9a4052c..581f2200 100644
--- a/rust/networking/src/discovery.rs
+++ b/rust/networking/src/discovery.rs
@@ -1,5 +1,4 @@
use crate::ext::MultiaddrExt;
-use crate::keep_alive;
use delegate::delegate;
use either::Either;
use futures::FutureExt;
diff --git a/rust/networking/src/keep_alive.rs b/rust/networking/src/keep_alive.rs
deleted file mode 100644
index 881b11d7..00000000
--- a/rust/networking/src/keep_alive.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-use delegate::delegate;
-use libp2p::swarm::handler::ConnectionEvent;
-use libp2p::swarm::{ConnectionHandlerEvent, SubstreamProtocol, dummy, handler};
-use std::task::{Context, Poll};
-
-/// An implementation of [`ConnectionHandler`] that doesn't handle any protocols, but it keeps
-/// the connection alive.
-#[derive(Clone)]
-#[repr(transparent)]
-pub struct ConnectionHandler(dummy::ConnectionHandler);
-
-impl ConnectionHandler {
- pub fn new() -> Self {
- ConnectionHandler(dummy::ConnectionHandler)
- }
-}
-
-impl handler::ConnectionHandler for ConnectionHandler {
- // delegate types and implementation mostly to dummy handler
- type FromBehaviour = <dummy::ConnectionHandler as handler::ConnectionHandler>::FromBehaviour;
- type ToBehaviour = <dummy::ConnectionHandler as handler::ConnectionHandler>::ToBehaviour;
- type InboundProtocol =
- <dummy::ConnectionHandler as handler::ConnectionHandler>::InboundProtocol;
- type OutboundProtocol =
- <dummy::ConnectionHandler as handler::ConnectionHandler>::OutboundProtocol;
- type InboundOpenInfo =
- <dummy::ConnectionHandler as handler::ConnectionHandler>::InboundOpenInfo;
- type OutboundOpenInfo =
- <dummy::ConnectionHandler as handler::ConnectionHandler>::OutboundOpenInfo;
-
- delegate! {
- to self.0 {
- fn listen_protocol(&self) -> SubstreamProtocol<Self::InboundProtocol, Self::InboundOpenInfo>;
- fn poll(&mut self, cx: &mut Context<'_>) -> Poll<ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>>;
- fn on_behaviour_event(&mut self, event: Self::FromBehaviour);
- fn on_connection_event(&mut self, event: ConnectionEvent<Self::InboundProtocol, Self::OutboundProtocol, Self::InboundOpenInfo, Self::OutboundOpenInfo>);
- }
- }
-
- // specifically override this to force connection to stay alive
- fn connection_keep_alive(&self) -> bool {
- true
- }
-}
diff --git a/rust/networking/src/lib.rs b/rust/networking/src/lib.rs
index 59b83817..6ff8c901 100644
--- a/rust/networking/src/lib.rs
+++ b/rust/networking/src/lib.rs
@@ -3,19 +3,7 @@
//! this is here as a placeholder documentation
//!
//!
-
-// enable Rust-unstable features for convenience
-#![feature(trait_alias)]
-// #![feature(stmt_expr_attributes)]
-// #![feature(unboxed_closures)]
-// #![feature(assert_matches)]
-// #![feature(async_fn_in_dyn_trait)]
-// #![feature(async_for_loop)]
-// #![feature(auto_traits)]
-// #![feature(negative_impls)]
-
pub mod discovery;
-pub mod keep_alive;
pub mod swarm;
/// Namespace for all the type/trait aliases used by this crate.
@@ -54,11 +42,3 @@ pub(crate) mod ext {
}
}
}
-
-pub(crate) mod private {
- #![allow(dead_code)]
-
- /// Sealed traits support
- pub trait Sealed {}
- impl<T: ?Sized> Sealed for T {}
-}
← 3addeade Update mlx-lm to 0.30.7 (#1520)
·
back to Exo
·
prioritize official model cards over custom model cards 5cbd6377 →