- use color-eyre

This commit is contained in:
w.pomp
2026-01-23 11:16:10 +01:00
parent 86f1c50c30
commit 8883ae7e5e
4 changed files with 38 additions and 32 deletions

View File

@@ -52,8 +52,8 @@ jobs:
platform: platform:
- runner: windows-latest - runner: windows-latest
target: x64 target: x64
# - runner: windows-latest # - runner: windows-11-arm
# target: x86 # target: aarch64
steps: steps:
- uses: actions/checkout@v6 - uses: actions/checkout@v6
- uses: actions/setup-python@v6 - uses: actions/setup-python@v6

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "tiffwrite" name = "tiffwrite"
version = "2025.12.0" version = "2026.1.1"
edition = "2024" edition = "2024"
rust-version = "1.85.1" rust-version = "1.85.1"
authors = ["Wim Pomp <w.pomp@nki.nl>"] authors = ["Wim Pomp <w.pomp@nki.nl>"]
@@ -20,6 +20,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
colorcet = "0.2" colorcet = "0.2"
colorgrad = "0.8" colorgrad = "0.8"
color-eyre = { version = "0.6", optional = true }
chrono = "0.4" chrono = "0.4"
css-color = "0.2" css-color = "0.2"
flate2 = "1" flate2 = "1"
@@ -32,8 +33,8 @@ zstd = "0.13"
[dependencies.pyo3] [dependencies.pyo3]
version = "0.27" 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 optional = true
[features] [features]
python = ["dep:pyo3", "dep:numpy"] python = ["dep:pyo3", "dep:numpy", "dep:color-eyre"]

View File

@@ -135,8 +135,8 @@ impl Tag {
} }
} }
pub fn byte(code: u16, value: &Vec<u8>) -> Self { pub fn byte(code: u16, value: &[u8]) -> Self {
Tag::new(code, value.to_owned(), 1) Tag::new(code, value.to_vec(), 1)
} }
pub fn ascii(code: u16, value: &str) -> Self { pub fn ascii(code: u16, value: &str) -> Self {

View File

@@ -6,7 +6,7 @@ use pyo3::prelude::*;
impl From<crate::error::Error> for PyErr { impl From<crate::error::Error> for PyErr {
fn from(err: crate::error::Error) -> PyErr { fn from(err: crate::error::Error) -> PyErr {
PyErr::new::<PyValueError, _>(err.to_string()) color_eyre::eyre::Report::from(err).into()
} }
} }
@@ -333,39 +333,44 @@ impl PyIJTiffFile {
} }
macro_rules! impl_save { macro_rules! impl_save {
($T:ty, $t:ident) => { ($($T:ty: $t:ident $(,)?)*) => {
#[pymethods] $(
impl PyIJTiffFile { #[pymethods]
fn $t( impl PyIJTiffFile {
&mut self, fn $t(
frame: PyArrayLike2<$T, AllowTypeChange>, &mut self,
c: usize, frame: PyArrayLike2<$T, AllowTypeChange>,
t: usize, c: usize,
z: usize, t: usize,
) -> PyResult<()> { z: usize,
if let Some(ijtifffile) = self.ijtifffile.as_mut() { ) -> PyResult<()> {
ijtifffile.save(frame.as_array(), c, t, z)?; 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! {
impl_save!(u16, save_u16); u8: save_u8,
impl_save!(u32, save_u32); u16: save_u16,
impl_save!(u64, save_u64); u32: save_u32,
impl_save!(i8, save_i8); u64: save_u64,
impl_save!(i16, save_i16); i8: save_i8,
impl_save!(i32, save_i32); i16: save_i16,
impl_save!(i64, save_i64); i32: save_i32,
impl_save!(f32, save_f32); i64: save_i64,
impl_save!(f64, save_f64); f32: save_f32,
f64: save_f64,
}
#[pymodule] #[pymodule]
#[pyo3(name = "tiffwrite_rs")] #[pyo3(name = "tiffwrite_rs")]
fn tiffwrite_rs(m: &Bound<'_, PyModule>) -> PyResult<()> { fn tiffwrite_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
color_eyre::install()?;
m.add_class::<PyTag>()?; m.add_class::<PyTag>()?;
m.add_class::<PyIJTiffFile>()?; m.add_class::<PyIJTiffFile>()?;
Ok(()) Ok(())