-
Notifications
You must be signed in to change notification settings - Fork 2
added Endianness access from IFD to python #106
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
5487c3a
caa423c
9b17ba4
4d0eabd
a34b398
ae9e557
0ca7e74
d63e299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
use async_tiff::tiff::tags::{ | ||
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, ResolutionUnit, | ||
SampleFormat, | ||
use async_tiff::{ | ||
reader::Endianness, | ||
tiff::tags::{ | ||
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Predictor, | ||
ResolutionUnit, SampleFormat, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep this as module imports instead of crate imports. |
||
}; | ||
use pyo3::prelude::*; | ||
use pyo3::types::{PyString, PyTuple}; | ||
use pyo3::{intern, IntoPyObjectExt}; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub(crate) struct PyEndianness(Endianness); | ||
|
||
impl From<Endianness> for PyEndianness { | ||
fn from(value: Endianness) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<PyEndianness> for Endianness { | ||
fn from(value: PyEndianness) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl<'py> IntoPyObject<'py> for PyEndianness { | ||
type Target = PyAny; | ||
type Output = Bound<'py, PyAny>; | ||
type Error = PyErr; | ||
|
||
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> { | ||
// import the python module | ||
let enums_mod = py.import(intern!(py, "async_tiff.enums"))?; | ||
// get our python enum | ||
let enum_cls = enums_mod.getattr(intern!(py, "Endianness"))?; | ||
match self.0 { | ||
Endianness::LittleEndian => enum_cls.getattr(intern!(py, "LittleEndian")), | ||
Endianness::BigEndian => enum_cls.getattr(intern!(py, "BigEndian")), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub(crate) struct PyCompressionMethod(CompressionMethod); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -4,8 +4,8 @@ use async_tiff::ImageFileDirectory; | |||
use pyo3::prelude::*; | ||||
|
||||
use crate::enums::{ | ||||
PyCompressionMethod, PyPhotometricInterpretation, PyPlanarConfiguration, PyPredictor, | ||||
PyResolutionUnit, PySampleFormat, | ||||
PyCompressionMethod, PyEndianness, PyPhotometricInterpretation, PyPlanarConfiguration, | ||||
PyPredictor, PyResolutionUnit, PySampleFormat, | ||||
}; | ||||
use crate::geo::PyGeoKeyDirectory; | ||||
use crate::value::PyValue; | ||||
|
@@ -15,6 +15,11 @@ pub(crate) struct PyImageFileDirectory(ImageFileDirectory); | |||
|
||||
#[pymethods] | ||||
impl PyImageFileDirectory { | ||||
#[getter] | ||||
pub fn endianness(&self) -> PyEndianness { | ||||
self.0.endianness().into() | ||||
} | ||||
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I mean you need to describe this here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that (lines 15-16, also comment). What I meant is a |
||||
|
||||
#[getter] | ||||
pub fn new_subfile_type(&self) -> Option<u32> { | ||||
self.0.new_subfile_type() | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add Python formatting to CI; as this would fail
black
/ruff fmt
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you opened an issue for that. I could pull it into this PR though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't know how to do that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a separate PR anyways. You can look at https://github.com/developmentseed/obstore/blob/ec7dd298f62bf48a23dd677d3780540ece883bfb/.pre-commit-config.yaml#L20-L25 and https://github.com/developmentseed/obstore/blob/ec7dd298f62bf48a23dd677d3780540ece883bfb/.github/workflows/test-python.yml#L17-L39