Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade PyO3 #211

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 32 additions & 101 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions mitmproxy-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ anyhow = { version = "1.0.93", features = ["backtrace"] }
data-encoding = "2.6.0"
log = "0.4.22"
once_cell = "1"
pyo3 = { version = "0.21", features = ["abi3", "abi3-py310", "anyhow", "experimental-declarative-modules"] }
pyo3-asyncio-0-21 = { version = "0.21", features = ["tokio-runtime", "testing", "attributes"] }
pyo3-log = "0.11.0"
pyo3 = { version = "0.23", features = ["abi3", "abi3-py310", "anyhow"] }
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime", "testing", "attributes"] }
pyo3-log = "0.12.0"
rand_core = { version = "0.6.4", features = ["getrandom"] }
tokio = { version = "1.41", features = ["macros", "net", "rt-multi-thread", "sync"] }
boringtun = "0.6"
Expand Down
2 changes: 1 addition & 1 deletion mitmproxy-rs/pytests/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static _LOGGER: LazyLock<Mutex<&'static TestLogger>> = LazyLock::new(|| {
});

/// Initialize the logger.
/// pyo3-asyncio tests all run in parallel in the same runtime, so we use a mutex to ensure
/// pyo3_async_runtimes tests all run in parallel in the same runtime, so we use a mutex to ensure
/// that only one test that uses TestLogger runs at the same time.
pub async fn setup_logger() -> MutexGuard<'static, &'static TestLogger> {
let logger = _LOGGER.lock().await;
Expand Down
30 changes: 13 additions & 17 deletions mitmproxy-rs/pytests/test_task.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod logger;

mod tests {

use std::ffi::CString;
use std::future::Future;

use mitmproxy::messages::{ConnectionId, TransportEvent, TunnelInfo};
Expand All @@ -14,7 +14,7 @@ mod tests {
use mitmproxy::shutdown;
use tokio::sync::mpsc;

#[pyo3_asyncio_0_21::tokio::test]
#[pyo3_async_runtimes::tokio::test]
async fn test_handler_invalid_signature() -> PyResult<()> {
let logger = setup_logger().await;
_test_task_error_handling(
Expand All @@ -26,7 +26,7 @@ mod tests {
Ok(())
}

#[pyo3_asyncio_0_21::tokio::test]
#[pyo3_async_runtimes::tokio::test]
async fn test_handler_runtime_error() -> PyResult<()> {
let logger = setup_logger().await;
_test_task_error_handling(
Expand All @@ -38,7 +38,7 @@ mod tests {
Ok(())
}

#[pyo3_asyncio_0_21::tokio::test]
#[pyo3_async_runtimes::tokio::test]
async fn test_handler_cancelled() -> PyResult<()> {
let logger = setup_logger().await;
_test_task_error_handling(
Expand All @@ -63,19 +63,15 @@ mod tests {
let (event_tx, event_rx) = mpsc::channel(1);
let (shutdown_tx, shutdown_rx) = shutdown::channel();

let conn_handler = Python::with_gil(|py| {
let locals = PyDict::new_bound(py);
py.run_bound(code, None, Some(&locals)).unwrap();
locals.get_item("handler").unwrap().unwrap().to_object(py)
let (tcp_handler, udp_handler) = Python::with_gil(|py| {
let locals = PyDict::new(py);
let code = CString::new(code).unwrap();
py.run(&code, None, Some(&locals)).unwrap();
let handler = locals.get_item("handler").unwrap().unwrap().unbind();
(handler.clone_ref(py), handler)
});

let task = PyInteropTask::new(
command_tx,
event_rx,
conn_handler.clone(),
conn_handler,
shutdown_rx,
)?;
let task = PyInteropTask::new(command_tx, event_rx, tcp_handler, udp_handler, shutdown_rx)?;
let task = tokio::spawn(task.run());

event_tx
Expand All @@ -99,7 +95,7 @@ mod tests {
}
}

#[pyo3_asyncio_0_21::tokio::main]
#[pyo3_async_runtimes::tokio::main]
async fn main() -> pyo3::PyResult<()> {
pyo3_asyncio_0_21::testing::main().await
pyo3_async_runtimes::testing::main().await
}
Loading
Loading