Skip to content

Commit

Permalink
updated as per linting report
Browse files Browse the repository at this point in the history
  • Loading branch information
tahseenadit committed May 13, 2024
1 parent 994b4c3 commit 6f6f550
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
32 changes: 13 additions & 19 deletions imageio/plugins/rawpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RawPyPlugin(PluginV3):
RawPyPlugin.read
"""

def __init__(self, request: Request) -> None:
"""Instantiates a new rawpy plugin object
Expand All @@ -40,19 +41,19 @@ def __init__(self, request: Request) -> None:
if request.mode.io_mode == IOMode.read:
try:
self._image_file = rawpy.imread(request.get_file())
except (rawpy.NotSupportedError, rawpy.LibRawFileUnsupportedError, rawpy.LibRawIOError):
except (
rawpy.NotSupportedError,
rawpy.LibRawFileUnsupportedError,
rawpy.LibRawIOError,
):
if request._uri_type == URI_BYTES:
raise InitializationError(
"RawPy can not read the provided bytes."
) from None
raise InitializationError("RawPy can not read the provided bytes.") from None
else:
raise InitializationError(
f"RawPy can not read {request.raw_uri}."
) from None
elif request.mode.io_mode == IOMode.write:
raise InitializationError(
"RawPy does not support writing."
) from None
raise InitializationError("RawPy does not support writing.") from None

def close(self) -> None:
if self._image_file:
Expand All @@ -75,18 +76,14 @@ def read(self, *, index: int = 0, **kwargs) -> np.ndarray:
nd_image = self._image_file.postprocess(**kwargs)
except Exception:
pass

if index is Ellipsis:
nd_image = nd_image[None, ...]

return nd_image

def write(
self,
ndimage: Union[ArrayLike, List[ArrayLike]]
) -> Optional[bytes]:
"""RawPy does not support writing.
"""
def write(self, ndimage: Union[ArrayLike, List[ArrayLike]]) -> Optional[bytes]:
"""RawPy does not support writing."""
raise NotImplementedError()

def iter(self) -> Iterator[np.ndarray]:
Expand Down Expand Up @@ -164,7 +161,7 @@ def metadata(
metadata.pop("white_level", None)

return metadata

def properties(self, index: int = None) -> ImageProperties:
"""Standardized ndimage metadata
Expand All @@ -187,7 +184,4 @@ def properties(self, index: int = None) -> ImageProperties:

dtype = self._image_file.raw_image.dtype

return ImageProperties(
shape=shape,
dtype=dtype
)
return ImageProperties(shape=shape, dtype=dtype)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"tifffile": ["tifffile"],
"pyav": ["av"],
"pillow-heif": ["pillow-heif"],
"rawpy": ["rawpy"]
"rawpy": ["rawpy"],
}

cpython_only_plugins = {
Expand Down
31 changes: 13 additions & 18 deletions tests/test_rawpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
@pytest.mark.parametrize(
"im_in",
[
("Nikon_uncompressed.nef"),
("Blackmagic.dng"),
("Canon_Powershot.CRW"),
("Pentax_compressed.PEF"),
("Nikon_uncompressed.nef"),
("Blackmagic.dng"),
("Canon_Powershot.CRW"),
("Pentax_compressed.PEF"),
],
)
def test_read(test_images, im_in):
"""Test for reading .nef file from .test_images dir.
"""
"""Test for reading .nef file from .test_images dir."""
# Construct image path
im_path = test_images / im_in

Expand All @@ -32,15 +31,14 @@ def test_read(test_images, im_in):
@pytest.mark.parametrize(
"im_in",
[
("Nikon_uncompressed.nef"),
("Blackmagic.dng"),
("Canon_Powershot.CRW"),
("Pentax_compressed.PEF"),
("Nikon_uncompressed.nef"),
("Blackmagic.dng"),
("Canon_Powershot.CRW"),
("Pentax_compressed.PEF"),
],
)
def test_read_with_default_index(test_images, im_in):
"""Test for reading .nef file from .test_images dir.
"""
"""Test for reading .nef file from .test_images dir."""
# Construct image path
im_path = test_images / im_in

Expand All @@ -51,8 +49,7 @@ def test_read_with_default_index(test_images, im_in):


def test_iter(test_images):
"""Test for the iter function of rawpy plugin.
"""
"""Test for the iter function of rawpy plugin."""

# Construct image path
im_path = test_images / "Blackmagic.dng"
Expand All @@ -61,8 +58,7 @@ def test_iter(test_images):


def test_properties(test_images):
"""Test for reading properties of a raw image from .test_images dir.
"""
"""Test for reading properties of a raw image from .test_images dir."""
# Construct image path
im_path = test_images / "Nikon_uncompressed.nef"

Expand All @@ -73,8 +69,7 @@ def test_properties(test_images):


def test_metadata(test_images):
"""Test for reading metadata of a raw image from .test_images dir.
"""
"""Test for reading metadata of a raw image from .test_images dir."""
# Construct image path
im_path = test_images / "Nikon_uncompressed.nef"

Expand Down

0 comments on commit 6f6f550

Please sign in to comment.