- 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:
- 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

View File

@@ -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 <w.pomp@nki.nl>"]
@@ -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"]

View File

@@ -135,8 +135,8 @@ impl Tag {
}
}
pub fn byte(code: u16, value: &Vec<u8>) -> 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 {

View File

@@ -6,7 +6,7 @@ use pyo3::prelude::*;
impl From<crate::error::Error> for 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 {
($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::<PyTag>()?;
m.add_class::<PyIJTiffFile>()?;
Ok(())