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 api usage #215

Merged
merged 10 commits into from
Jan 3, 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
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())
))
}
Loading