Skip to content

Commit

Permalink
Merge pull request #1405 from girder/report-jar-version
Browse files Browse the repository at this point in the history
Get bioformats jar version if bioformats was started
  • Loading branch information
manthey authored Dec 13, 2023
2 parents 2701d45 + a1c9dd6 commit de9ef4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 13 additions & 1 deletion sources/bioformats/large_image_source_bioformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -53,6 +55,7 @@
javabridge = None

_javabridgeStarted = None
_bioformatsVersion = None
_openImages = []


Expand Down Expand Up @@ -110,14 +113,23 @@ 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.
global bioformats
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

Expand Down
7 changes: 7 additions & 0 deletions test/test_source_bioformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit de9ef4a

Please sign in to comment.