Skip to content

Commit eab1985

Browse files
authored
Upgrade pyo3 api usage (mitmproxy#215)
1 parent 8c22b44 commit eab1985

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

mitmproxy-linux/build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,16 @@ fn main() {
8686
let stderr = std::thread::spawn(move || {
8787
for line in stderr.lines() {
8888
let line = line.unwrap();
89-
let skip = line.contains("Compiling ") || line.contains("Finished `");
89+
let skip = line.contains("info: latest update on")
90+
|| line.contains("syncing channel updates")
91+
|| line.contains("downloading component")
92+
|| line.contains("installing component")
93+
|| line.contains("Updating crates.io index")
94+
|| line.contains("Updating git repository")
95+
|| line.contains("Downloading")
96+
|| line.contains("Downloaded")
97+
|| line.contains("Compiling ")
98+
|| line.contains("Finished `");
9099
if !skip {
91100
println!("cargo:warning={line}");
92101
}

mitmproxy-rs/src/process_info.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::path::{Path, PathBuf};
22

3-
use anyhow::Result;
3+
#[cfg(any(windows, target_os = "macos"))]
4+
use anyhow::Context;
45
use pyo3::prelude::*;
6+
#[cfg(any(windows, target_os = "macos"))]
7+
use pyo3::IntoPyObjectExt;
58

69
#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
710
use mitmproxy::processes;
@@ -67,18 +70,17 @@ pub fn active_executables() -> PyResult<Vec<Process>> {
6770
/// *Availability: Windows, macOS*
6871
#[pyfunction]
6972
#[allow(unused_variables)]
70-
pub fn executable_icon(path: PathBuf) -> Result<PyObject> {
73+
pub fn executable_icon(py: Python<'_>, path: PathBuf) -> PyResult<PyObject> {
7174
#[cfg(any(windows, target_os = "macos"))]
7275
{
7376
let mut icon_cache = processes::ICON_CACHE.lock().unwrap();
74-
let png_bytes = icon_cache.get_png(path)?;
75-
Ok(Python::with_gil(|py| {
76-
pyo3::types::PyBytes::new(py, png_bytes).to_object(py)
77-
}))
77+
icon_cache
78+
.get_png(path)
79+
.context("failed to get image")?
80+
.into_py_any(py)
7881
}
7982
#[cfg(not(any(windows, target_os = "macos")))]
8083
Err(pyo3::exceptions::PyNotImplementedError::new_err(
8184
"executable_icon is only available on Windows",
82-
)
83-
.into())
85+
))
8486
}

0 commit comments

Comments
 (0)