Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce bioformats keeping file handles open #1492

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ repos:
- '--options'
- './girder/girder_large_image/web_client/package.json'
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py38-plus
- --keep-percent-format
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.0
rev: v0.3.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -81,11 +81,11 @@ repos:
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add a dependency to the zarr source to read more compression types ([#1480](../../pull/1480))
- Guard fetching internal metadata on zarr sources that have less data ([#1481](../../pull/1481))
- Add a method to list registered extensions and mimetypes ([#1488](../../pull/1488))
- Reduce bioformats keeping file handles open ([#1492](../../pull/1492))

### Changes
- Prohibit bioformats from reading zip directly ([#1491](../../pull/1491))
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exclude = [
"*/web_client/*",
"*/*egg*/*",
]
ignore = [
lint.ignore = [
"B017",
"B026",
"B904",
Expand Down Expand Up @@ -38,7 +38,7 @@ ignore = [
"PT017",
]
line-length = 100
select = [
lint.select = [
"B", # bugbear
"C90", # mccabe
"D", # pydocstyle
Expand All @@ -61,14 +61,14 @@ select = [
"RSE",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# allow "useless expressions" as it shows output
# allow non-top level imports
# allow long lines
"docs/large_image_examples.ipynb" = ["B018", "E402", "E501"]

[tool.ruff.flake8-quotes]
[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 14
16 changes: 15 additions & 1 deletion sources/bioformats/large_image_source_bioformats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,21 @@ def __init__(self, path, **kwargs): # noqa
try:
javabridge.attach()
try:
self._bioimage = bioformats.ImageReader(largeImagePath)
self._bioimage = bioformats.ImageReader(largeImagePath, perform_init=False)
try:
# So this as a separate step so, if it fails, we can ask to
# open something that does not exist and bioformats will
# release some file handles.
self._bioimage.init_reader()
except Exception as exc:
try:
# Ask to open a file that should never exist
self._bioimage.rdr.setId('__\0__')
except Exception:
pass
self._bioimage.close()
self._bioimage = None
raise exc
except (AttributeError, OSError) as exc:
if not os.path.isfile(largeImagePath):
raise TileSourceFileNotFoundError(largeImagePath) from None
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ deps =
flake8-quotes
ruff
commands =
ruff large_image sources utilities girder girder_annotation examples docs test
ruff check large_image sources utilities girder girder_annotation examples docs test
flake8

[testenv:type]
Expand Down Expand Up @@ -213,7 +213,7 @@ skip_install = true
deps =
ruff
commands =
ruff large_image sources utilities girder girder_annotation examples docs test {posargs}
ruff check large_image sources utilities girder girder_annotation examples docs test {posargs}

[testenv:format]
description = Autoformat import order and autopep8
Expand All @@ -228,7 +228,7 @@ commands =
isort .
autopep8 -ria large_image sources utilities girder girder_annotation examples docs test
unify --in-place --recursive large_image sources utilities girder girder_annotation examples docs test
ruff large_image sources utilities girder girder_annotation examples docs test --fix
ruff check large_image sources utilities girder girder_annotation examples docs test --fix

[testenv:lintclient]
description = Lint the girder large_image plugin client
Expand Down