Skip to content

Commit

Permalink
Upgrade pyo3 api usage (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored Jan 3, 2025
1 parent 8c22b44 commit eab1985
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 10 additions & 1 deletion mitmproxy-linux/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ fn main() {
let stderr = std::thread::spawn(move || {
for line in stderr.lines() {
let line = line.unwrap();
let skip = line.contains("Compiling ") || line.contains("Finished `");
let skip = line.contains("info: latest update on")
|| line.contains("syncing channel updates")
|| line.contains("downloading component")
|| line.contains("installing component")
|| line.contains("Updating crates.io index")
|| line.contains("Updating git repository")
|| line.contains("Downloading")
|| line.contains("Downloaded")
|| line.contains("Compiling ")
|| line.contains("Finished `");
if !skip {
println!("cargo:warning={line}");
}
Expand Down
18 changes: 10 additions & 8 deletions mitmproxy-rs/src/process_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::path::{Path, PathBuf};

use anyhow::Result;
#[cfg(any(windows, target_os = "macos"))]
use anyhow::Context;
use pyo3::prelude::*;
#[cfg(any(windows, target_os = "macos"))]
use pyo3::IntoPyObjectExt;

#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
use mitmproxy::processes;
Expand Down Expand Up @@ -67,18 +70,17 @@ pub fn active_executables() -> PyResult<Vec<Process>> {
/// *Availability: Windows, macOS*
#[pyfunction]
#[allow(unused_variables)]
pub fn executable_icon(path: PathBuf) -> Result<PyObject> {
pub fn executable_icon(py: Python<'_>, path: PathBuf) -> PyResult<PyObject> {
#[cfg(any(windows, target_os = "macos"))]
{
let mut icon_cache = processes::ICON_CACHE.lock().unwrap();
let png_bytes = icon_cache.get_png(path)?;
Ok(Python::with_gil(|py| {
pyo3::types::PyBytes::new(py, png_bytes).to_object(py)
}))
icon_cache
.get_png(path)
.context("failed to get image")?
.into_py_any(py)
}
#[cfg(not(any(windows, target_os = "macos")))]
Err(pyo3::exceptions::PyNotImplementedError::new_err(
"executable_icon is only available on Windows",
)
.into())
))
}

0 comments on commit eab1985

Please sign in to comment.