From b4995da53edaad4e4b87eaccfe5cb5d47b443647 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Mon, 1 Jul 2024 22:39:26 +1000 Subject: [PATCH 1/2] Add support for both new and old napari syntax --- ome_zarr/reader.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index 55f84ec0..cb612351 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -3,6 +3,7 @@ import logging import math from abc import ABC +from importlib.metadata import PackageNotFoundError, version from typing import Any, Dict, Iterator, List, Optional, Type, Union, cast, overload import dask.array as da @@ -253,12 +254,19 @@ def __init__(self, node: Node) -> None: del properties[label_val]["label-value"] # TODO: a metadata transform should be provided by specific impls. + try: + napari_version = tuple(map(int, list(version("napari").split("."))))[ + :2 + ] # major and minor versions as int + except PackageNotFoundError: + napari_version = (0, 5) # default to 0.5+ if not installed + colormap_key = "colormap" if napari_version >= (0, 5) else "color" name = self.zarr.basename() node.metadata.update( { "visible": node.visible, "name": name, - "color": colors, + colormap_key: colors, "metadata": {"image": self.lookup("image", {}), "path": name}, } ) From 55e33284b580db542730f085b4112242873897c1 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Thu, 4 Jul 2024 18:54:17 +1000 Subject: [PATCH 2/2] fix version check --- ome_zarr/reader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index cb612351..48f2edf5 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -255,9 +255,9 @@ def __init__(self, node: Node) -> None: # TODO: a metadata transform should be provided by specific impls. try: - napari_version = tuple(map(int, list(version("napari").split("."))))[ - :2 - ] # major and minor versions as int + napari_version = tuple( + map(int, list(version("napari").split(".")[:2])) + ) # major and minor versions as int except PackageNotFoundError: napari_version = (0, 5) # default to 0.5+ if not installed colormap_key = "colormap" if napari_version >= (0, 5) else "color"