silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
119 stars 70 forks source link

silx.io.url: Added HSDS URL support #4119

Closed felix-engelmann closed 2 months ago

felix-engelmann commented 2 months ago

Silx internally supports h5pyd and therefore should be able to connect to a HSDS server with a http url.

However, when running e.g.

silx view http://hsds-server.tld/home/live  --debug

it crashes with

DEBUG:silx.gui.hdf5.Hdf5TreeModel:File 'http:///home/live' can't be read.
Traceback (most recent call last):
  File ".../silx/build/lib.linux-x86_64-3.11/silx/gui/hdf5/Hdf5TreeModel.py", line 733, in insertFile
    h5file = silx_io.open(filename)
             ^^^^^^^^^^^^^^^^^^^^^^
  File ".../silx/build/lib.linux-x86_64-3.11/silx/io/utils.py", line 687, in open
    return h5pyd.File(path, "r", endpoint=endpoint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.conda/envs/silx/lib/python3.11/site-packages/h5pyd/_hl/files.py", line 212, in __init__
    raise IOError(400, "relative paths are not valid")
OSError: [Errno 400] relative paths are not valid
ERROR:silx.app.view.main:400
DEBUG:silx.app.view.main:Backtrace
Traceback (most recent call last):
  File ".../silx/build/lib.linux-x86_64-3.11/silx/app/view/main.py", line 181, in mainQt
    window.appendFile(url.path())
  File ".../silx/build/lib.linux-x86_64-3.11/silx/app/view/Viewer.py", line 910, in appendFile
    self.__treeview.findHdf5TreeModel().appendFile(filename)
  File ".../silx/build/lib.linux-x86_64-3.11/silx/gui/hdf5/Hdf5TreeModel.py", line 749, in appendFile
    self.insertFile(filename, -1)
  File ".../silx/build/lib.linux-x86_64-3.11/silx/gui/hdf5/Hdf5TreeModel.py", line 733, in insertFile
    h5file = silx_io.open(filename)
             ^^^^^^^^^^^^^^^^^^^^^^
  File ".../silx/build/lib.linux-x86_64-3.11/silx/io/utils.py", line 687, in open
    return h5pyd.File(path, "r", endpoint=endpoint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.conda/envs/silx/lib/python3.11/site-packages/h5pyd/_hl/files.py", line 212, in __init__
    raise IOError(400, "relative paths are not valid")
OSError: [Errno 400] relative paths are not valid

The main cause is, that silx.io.url.DataUrl is not able to parse a http url correctly.

This patch adds support for http urls which are then correctly displayed.

A minor fix is to provide h5pyd with an absolute url in utils.py instead of stripping the leading /

Unfortunately I did not find a public HSDS server to tests against and the leading / is not tripping any tests, so I assume it is still backwards compatible.

t20100 commented 2 months ago

Here is the PR on your branch: https://github.com/felix-engelmann/silx/pull/1