From 8883ae7e5e446b654e131c14ae89b0bd829f4dcd Mon Sep 17 00:00:00 2001 From: "w.pomp" Date: Fri, 23 Jan 2026 11:16:10 +0100 Subject: [PATCH] - use color-eyre --- .github/workflows/publish.yml | 4 +-- Cargo.toml | 7 +++-- src/lib.rs | 4 +-- src/py.rs | 55 +++++++++++++++++++---------------- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 14a7d0d..3a33e39 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -52,8 +52,8 @@ jobs: platform: - runner: windows-latest target: x64 -# - runner: windows-latest -# target: x86 +# - runner: windows-11-arm +# target: aarch64 steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 diff --git a/Cargo.toml b/Cargo.toml index 6b9d1b1..cb596b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiffwrite" -version = "2025.12.0" +version = "2026.1.1" edition = "2024" rust-version = "1.85.1" authors = ["Wim Pomp "] @@ -20,6 +20,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] colorcet = "0.2" colorgrad = "0.8" +color-eyre = { version = "0.6", optional = true } chrono = "0.4" css-color = "0.2" flate2 = "1" @@ -32,8 +33,8 @@ zstd = "0.13" [dependencies.pyo3] version = "0.27" -features = ["extension-module", "abi3-py310", "generate-import-lib", "anyhow", "multiple-pymethods"] +features = ["extension-module", "abi3-py310", "eyre", "generate-import-lib", "multiple-pymethods"] optional = true [features] -python = ["dep:pyo3", "dep:numpy"] +python = ["dep:pyo3", "dep:numpy", "dep:color-eyre"] diff --git a/src/lib.rs b/src/lib.rs index e4fc544..8e431eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -135,8 +135,8 @@ impl Tag { } } - pub fn byte(code: u16, value: &Vec) -> Self { - Tag::new(code, value.to_owned(), 1) + pub fn byte(code: u16, value: &[u8]) -> Self { + Tag::new(code, value.to_vec(), 1) } pub fn ascii(code: u16, value: &str) -> Self { diff --git a/src/py.rs b/src/py.rs index 33fd70e..5bc3665 100644 --- a/src/py.rs +++ b/src/py.rs @@ -6,7 +6,7 @@ use pyo3::prelude::*; impl From for PyErr { fn from(err: crate::error::Error) -> PyErr { - PyErr::new::(err.to_string()) + color_eyre::eyre::Report::from(err).into() } } @@ -333,39 +333,44 @@ impl PyIJTiffFile { } macro_rules! impl_save { - ($T:ty, $t:ident) => { - #[pymethods] - impl PyIJTiffFile { - fn $t( - &mut self, - frame: PyArrayLike2<$T, AllowTypeChange>, - c: usize, - t: usize, - z: usize, - ) -> PyResult<()> { - if let Some(ijtifffile) = self.ijtifffile.as_mut() { - ijtifffile.save(frame.as_array(), c, t, z)?; + ($($T:ty: $t:ident $(,)?)*) => { + $( + #[pymethods] + impl PyIJTiffFile { + fn $t( + &mut self, + frame: PyArrayLike2<$T, AllowTypeChange>, + c: usize, + t: usize, + z: usize, + ) -> PyResult<()> { + if let Some(ijtifffile) = self.ijtifffile.as_mut() { + ijtifffile.save(frame.as_array(), c, t, z)?; + } + Ok(()) } - Ok(()) } - } + )* }; } -impl_save!(u8, save_u8); -impl_save!(u16, save_u16); -impl_save!(u32, save_u32); -impl_save!(u64, save_u64); -impl_save!(i8, save_i8); -impl_save!(i16, save_i16); -impl_save!(i32, save_i32); -impl_save!(i64, save_i64); -impl_save!(f32, save_f32); -impl_save!(f64, save_f64); +impl_save! { + u8: save_u8, + u16: save_u16, + u32: save_u32, + u64: save_u64, + i8: save_i8, + i16: save_i16, + i32: save_i32, + i64: save_i64, + f32: save_f32, + f64: save_f64, +} #[pymodule] #[pyo3(name = "tiffwrite_rs")] fn tiffwrite_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { + color_eyre::install()?; m.add_class::()?; m.add_class::()?; Ok(())