From 2be7010a17b3e61e935521729526f5e0341299e7 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 15 May 2023 13:54:22 +0200 Subject: [PATCH] Check libhdf5 version for support of the `locking` argument --- jupyterlab_h5web/handlers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jupyterlab_h5web/handlers.py b/jupyterlab_h5web/handlers.py index 1f6fdec..884ec23 100644 --- a/jupyterlab_h5web/handlers.py +++ b/jupyterlab_h5web/handlers.py @@ -1,3 +1,4 @@ +import h5py from tornado.web import authenticated, MissingArgumentError from jupyter_server.base.handlers import APIHandler from jupyter_server.utils import url_path_join @@ -15,6 +16,12 @@ from .utils import as_absolute_path, create_error +H5PY_HAS_FILE_LOCKING_ARG = h5py.version.hdf5_version_tuple >= (1, 12, 1) or ( + h5py.version.hdf5_version_tuple[:2] == (1, 10) + and h5py.version.hdf5_version_tuple[2] >= 7 +) + + class BaseHandler(APIHandler): def initialize(self, base_dir: Path) -> None: self.base_dir = base_dir @@ -33,7 +40,7 @@ def get(self): as_absolute_path(self.base_dir, Path(file_path)), path, create_error, - h5py_options={"locking": False}, + h5py_options={"locking": False} if H5PY_HAS_FILE_LOCKING_ARG else {}, ) as content: payload = self.parse_content(content)