From a1c9dd6a8640eab91b3d617a02eb72aead55d11e Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 11 Dec 2023 16:00:15 -0500 Subject: [PATCH] Get bioformats jar version if bioformats was started --- CHANGELOG.md | 1 + .../large_image_source_bioformats/__init__.py | 14 +++++++++++++- test/test_source_bioformats.py | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91cdeed17..f219b69f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Improve checks for formats we shouldn't read ([#1399](../../pull/1399)) - Support negative x, y in addTile ([#1401](../../pull/1401)) - Add a utility function for getting loggers ([#1403](../../pull/1403)) +- Get bioformats jar version if bioformats was started ([#1405](../../pull/1405)) ### Changes - Use an enum for priority constants ([#1400](../../pull/1400)) diff --git a/sources/bioformats/large_image_source_bioformats/__init__.py b/sources/bioformats/large_image_source_bioformats/__init__.py index 477888bde..c52576b63 100644 --- a/sources/bioformats/large_image_source_bioformats/__init__.py +++ b/sources/bioformats/large_image_source_bioformats/__init__.py @@ -26,10 +26,12 @@ import logging import math import os +import pathlib import re import threading import types import weakref +import zipfile from importlib.metadata import PackageNotFoundError from importlib.metadata import version as _importlib_version @@ -53,6 +55,7 @@ javabridge = None _javabridgeStarted = None +_bioformatsVersion = None _openImages = [] @@ -110,7 +113,7 @@ def _reduceLogging(): def _startJavabridge(logger): - global _javabridgeStarted + global _javabridgeStarted, _bioformatsVersion if _javabridgeStarted is None: # Only import these when first asked. They are slow to import. @@ -118,6 +121,15 @@ def _startJavabridge(logger): global javabridge if bioformats is None: import bioformats + try: + _bioformatsVersion = zipfile.ZipFile( + pathlib.Path(bioformats.__file__).parent / + 'jars/bioformats_package.jar', + ).open('META-INF/MANIFEST.MF').read(8192).split( + b'Implementation-Version: ')[1].split()[0].decode() + logger.info('Bioformats.jar version: %s', _bioformatsVersion) + except Exception: + pass if javabridge is None: import javabridge diff --git a/test/test_source_bioformats.py b/test/test_source_bioformats.py index 975100e51..09aa5862f 100644 --- a/test/test_source_bioformats.py +++ b/test/test_source_bioformats.py @@ -25,3 +25,10 @@ def testInternalMetadata(): source = large_image_source_bioformats.open(imagePath) metadata = source.getInternalMetadata() assert 'sizeColorPlanes' in metadata + + +def testBioformatsJarVersion(): + import large_image_source_bioformats + + datastore.fetch('HENormalN801.czi') + assert '.' in large_image_source_bioformats._bioformatsVersion