- workflow updates
PyTest / pytest (3.12) (push) Failing after 17s
PyTest / pytest (3.14) (push) Failing after 22s
PyTest / pytest (3.10) (push) Has been cancelled

- python stubs
This commit is contained in:
Wim Pomp
2026-05-09 13:00:47 +02:00
parent 2fc0bf8c9f
commit 91f863366d
11 changed files with 208 additions and 7 deletions
+26
View File
@@ -3,6 +3,9 @@ use num::{Complex, FromPrimitive, Rational32};
use numpy::{AllowTypeChange, PyArrayLike2};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
use pyo3_stub_gen::{StubGenConfig, StubInfo};
use std::path::PathBuf;
impl From<crate::error::Error> for PyErr {
fn from(err: crate::error::Error) -> PyErr {
@@ -10,6 +13,7 @@ impl From<crate::error::Error> for PyErr {
}
}
#[gen_stub_pyclass]
#[pyclass(name = "Tag", module = "tiffwrite_rs", subclass, from_py_object)]
#[derive(Clone, Debug)]
struct PyTag {
@@ -17,6 +21,7 @@ struct PyTag {
}
/// Tiff tag, use one of the constructors to get a tag of a specific type
#[gen_stub_pymethods]
#[pymethods]
impl PyTag {
#[staticmethod]
@@ -162,12 +167,14 @@ impl PyTag {
}
}
#[gen_stub_pyclass]
#[pyclass(name = "IJTiffFile", module = "tiffwrite_rs", subclass)]
#[derive(Debug)]
struct PyIJTiffFile {
ijtifffile: Option<IJTiffFile>,
}
#[gen_stub_pymethods]
#[pymethods]
impl PyIJTiffFile {
#[new]
@@ -333,10 +340,12 @@ impl PyIJTiffFile {
macro_rules! impl_save {
($($T:ty: $t:ident $(,)?)*) => {
$(
#[gen_stub_pymethods]
#[pymethods]
impl PyIJTiffFile {
fn $t(
&mut self,
#[gen_stub(override_type(type_repr="numpy.typing.ArrayLike", imports=("numpy", "numpy.typing")))]
frame: PyArrayLike2<$T, AllowTypeChange>,
c: usize,
t: usize,
@@ -365,11 +374,28 @@ impl_save! {
f64: save_f64,
}
/// generates tiffwrite/tiffwrite_rs.pyi
#[pyfunction]
fn generate_stub(dest_path: String) -> PyResult<()> {
StubInfo::from_project_root(
"tiffwrite_rs".to_string(),
PathBuf::from(dest_path).join("py"),
true,
StubGenConfig::default(),
)
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))?
.generate()
.map_err(|e| PyValueError::new_err(format!("{:?}", e)))
}
#[pymodule]
#[pyo3(name = "tiffwrite_rs")]
mod tiffwrite_rs {
use pyo3::prelude::*;
#[pymodule_export]
use super::generate_stub;
#[pymodule_export]
use super::PyTag;