Skip to content

Commit

Permalink
Move numpy and pillow requirements to new extended-assertions extra
Browse files Browse the repository at this point in the history
together pysam, which is also conditionally imported in
``lib/galaxy/tool_util/verify/__init__.py`` .
  • Loading branch information
nsoranzo committed Mar 2, 2024
1 parent 1a3edae commit 62c610c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/galaxy/tool_util/verify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@
TYPE_CHECKING,
)

import numpy
from PIL import Image

try:
import numpy
except ImportError:
pass
try:
import pysam
except ImportError:
pysam = None # type: ignore[assignment]
pass
try:
from PIL import Image
except ImportError:
pass

from galaxy.tool_util.parser.util import (
DEFAULT_DELTA,
Expand Down Expand Up @@ -449,7 +454,7 @@ def files_contains(file1, file2, attributes=None):

def _multiobject_intersection_over_union(
mask1: "numpy.typing.NDArray", mask2: "numpy.typing.NDArray", repeat_reverse: bool = True
) -> List[numpy.floating]:
) -> List["numpy.floating"]:
iou_list = []
for label1 in numpy.unique(mask1):
cc1 = mask1 == label1
Expand All @@ -463,7 +468,7 @@ def _multiobject_intersection_over_union(
return iou_list


def intersection_over_union(mask1: "numpy.typing.NDArray", mask2: "numpy.typing.NDArray") -> numpy.floating:
def intersection_over_union(mask1: "numpy.typing.NDArray", mask2: "numpy.typing.NDArray") -> "numpy.floating":
assert mask1.dtype == mask2.dtype
assert mask1.ndim == mask2.ndim == 2
assert mask1.shape == mask2.shape
Expand All @@ -475,7 +480,7 @@ def intersection_over_union(mask1: "numpy.typing.NDArray", mask2: "numpy.typing.

def get_image_metric(
attributes: Dict[str, Any]
) -> Callable[["numpy.typing.NDArray", "numpy.typing.NDArray"], numpy.floating]:
) -> Callable[["numpy.typing.NDArray", "numpy.typing.NDArray"], "numpy.floating"]:
metric_name = attributes.get("metric", DEFAULT_METRIC)
metrics = {
"mae": lambda arr1, arr2: numpy.abs(arr1 - arr2).mean(),
Expand Down
2 changes: 1 addition & 1 deletion packages/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ while read -r package_dir || [ -n "$package_dir" ]; do # https://stackoverflow.
if [ "$package_dir" = "util" ]; then
pip install -e '.[template,jstree]'
elif [ "$package_dir" = "tool_util" ]; then
pip install -e '.[cwl,mulled,edam]'
pip install -e '.[cwl,mulled,edam,extended-assertions]'
else
pip install -e '.'
fi
Expand Down
6 changes: 4 additions & 2 deletions packages/tool_util/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ install_requires =
galaxy-util>=22.1
conda-package-streaming
lxml!=4.2.2
numpy
MarkupSafe
packaging
pillow
pydantic>=2,!=2.6.0,!=2.6.1
PyYAML
requests
Expand Down Expand Up @@ -68,6 +66,10 @@ mulled =
Whoosh
edam =
edam-ontology
extended-assertions =
numpy
pysam
pillow

[options.packages.find]
exclude =
Expand Down

0 comments on commit 62c610c

Please sign in to comment.