From 62c610c250737775475a167acf1dcbc1c356fc63 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 2 Mar 2024 01:58:41 +0000 Subject: [PATCH] Move numpy and pillow requirements to new extended-assertions extra together pysam, which is also conditionally imported in ``lib/galaxy/tool_util/verify/__init__.py`` . --- lib/galaxy/tool_util/verify/__init__.py | 19 ++++++++++++------- packages/test.sh | 2 +- packages/tool_util/setup.cfg | 6 ++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/tool_util/verify/__init__.py b/lib/galaxy/tool_util/verify/__init__.py index 7adfa3321904..976c8706b684 100644 --- a/lib/galaxy/tool_util/verify/__init__.py +++ b/lib/galaxy/tool_util/verify/__init__.py @@ -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, @@ -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 @@ -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 @@ -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(), diff --git a/packages/test.sh b/packages/test.sh index 5a64061bd51d..ae69d9b20516 100755 --- a/packages/test.sh +++ b/packages/test.sh @@ -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 diff --git a/packages/tool_util/setup.cfg b/packages/tool_util/setup.cfg index 2aecac71fbe0..5d6b9b9a378d 100644 --- a/packages/tool_util/setup.cfg +++ b/packages/tool_util/setup.cfg @@ -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 @@ -68,6 +66,10 @@ mulled = Whoosh edam = edam-ontology +extended-assertions = + numpy + pysam + pillow [options.packages.find] exclude =