Skip to content

Commit

Permalink
raise on import if platform dependencies are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Sep 24, 2023
1 parent d9f2225 commit 21a485e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mitmproxy-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn init_logger() -> PyResult<()> {
}

#[pymodule]
pub fn mitmproxy_rs(_py: Python, m: &PyModule) -> PyResult<()> {
pub fn mitmproxy_rs(py: Python, m: &PyModule) -> PyResult<()> {
// set up the Rust logger to send messages to the Python logger
init_logger()?;

Expand All @@ -56,5 +56,11 @@ pub fn mitmproxy_rs(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<tcp_stream::TcpStream>()?;
m.add_class::<datagram_transport::DatagramTransport>()?;

// Import platform-specific modules here so that missing dependencies are raising immediately.
#[cfg(target_os = "macos")]
py.import("mitmproxy_macos")?;
#[cfg(windows)]
py.import("mitmproxy_windows")?;

Ok(())
}

0 comments on commit 21a485e

Please sign in to comment.