Skip to content

Commit

Permalink
Remove usages of isjava
Browse files Browse the repository at this point in the history
And bump minimum scyjava version to 1.9.1.

As of scyjava 1.9.1, the work from scijava/scyjava#60 is integrated,
meaning such defensive checks around conversion are no longer necessary.

This reverts commit 85f0d5c,
titled "Work around jpype convert limitation", and closes #220.

It also removes some other usages of isjava, which are also not needed.
  • Loading branch information
ctrueden committed Jul 25, 2023
1 parent 75cedb6 commit afc7653
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies = [
"numpy",
"pandas",
"pyimagej >= 1.4.1",
"scyjava >= 1.8.1",
"scyjava >= 1.9.1",
# Version rules to avoid problems
"qtconsole != 5.4.2", # https://github.com/napari/napari/issues/5700
"typing_extensions != 4.6.0", # https://github.com/pydantic/pydantic/issues/5821
Expand Down
4 changes: 2 additions & 2 deletions src/napari_imagej/types/converters/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from napari.layers import Image
from napari.utils.colormaps import Colormap
from numpy import ones
from scyjava import Priority, isjava
from scyjava import Priority
from xarray import DataArray

from napari_imagej.java import ij, jc
Expand All @@ -19,7 +19,7 @@


@java_to_py_converter(
predicate=lambda obj: isjava(obj) and ij().convert().supports(obj, jc.DatasetView),
predicate=lambda obj: ij().convert().supports(obj, jc.DatasetView),
priority=Priority.VERY_HIGH + 1,
)
def _java_image_to_image_layer(image: Any) -> Image:
Expand Down
12 changes: 2 additions & 10 deletions src/napari_imagej/utilities/_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@
from napari.layers import Layer
from napari.utils._magicgui import get_layers
from pandas import DataFrame
from scyjava import (
JavaIterable,
JavaList,
JavaMap,
JavaSet,
is_arraylike,
isjava,
jstacktrace,
)
from scyjava import JavaIterable, JavaList, JavaMap, JavaSet, is_arraylike, jstacktrace

from napari_imagej.java import ij, jc
from napari_imagej.types.type_conversions import type_hint_for
Expand Down Expand Up @@ -397,7 +389,7 @@ def _add_param_metadata(metadata: dict, key: str, value: Any) -> None:
if value is None:
return
try:
py_value = ij().py.from_java(value) if isjava(value) else value
py_value = ij().py.from_java(value)
if isinstance(py_value, JavaMap):
py_value = dict(py_value)
elif isinstance(py_value, JavaSet):
Expand Down
7 changes: 3 additions & 4 deletions src/napari_imagej/widgets/napari_imagej.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from napari.layers import Layer
from qtpy.QtCore import QThread, Signal, Slot
from qtpy.QtWidgets import QTreeWidgetItem, QVBoxLayout, QWidget
from scyjava import isjava, jstacktrace, when_jvm_stops
from scyjava import jstacktrace, when_jvm_stops

from napari_imagej.java import ij, init_ij, jc
from napari_imagej.utilities._module_utils import _non_layer_widget
Expand Down Expand Up @@ -207,9 +207,8 @@ def _handle_ij_init_error(self, exc: Exception):
self.search.bar.finalize_on_error()
# Print thet error
title = "ImageJ could not be initialized, due to the following error:"
if isjava(exc):
exception_str = jstacktrace(exc)
else:
exception_str = jstacktrace(exc)
if not exception_str:
# NB 3-arg function needed in Python < 3.10
exception_list = format_exception(type(exc), exc, exc.__traceback__)
exception_str = "".join(exception_list)
Expand Down

0 comments on commit afc7653

Please sign in to comment.