audeering / audbackend

Manage file storage on different backends
https://audeering.github.io/audbackend/
Other
3 stars 0 forks source link

What should we do if a backend requires open() #216

Closed hagenw closed 5 months ago

hagenw commented 5 months ago

In https://github.com/audeering/audbackend/pull/204 we introduced open() and close() methods.

At the moment, I'm cleaning up the authentication process for Artifactory and thought that it would make sense to move the authentication from __init__() to open(). The problem, I'm experiencing with this approach is that I don't know how I should handle the case if a user does not call open(), but tries to directly access some file, e.g. with exists(). Should I raise a audbackend.BackenError and state that the backend needs to be first opened?

hagenw commented 5 months ago

On the other hand with authentication there is nothing that needs to be closed, so maybe I just leave it within __init__()?

frankenjoe commented 5 months ago

To me open() seems the better fit.

The problem, I'm experiencing with this approach is that I don't know how I should handle the case if a user does not call open(), but tries to directly access some file, e.g. with exists()

To me the safest solution would be that we make calling open() mandatory. I remember you were arguing that it could be annoying for a user to do so. But I don't see this a big issue here since you only have to call it once in the beginning of your application and usually the call is anyway hidden inside a package like audb.

hagenw commented 5 months ago

When making it mandatory, couldn't we integrate it again in __init__()? Then you can still use it with with, or you call close() at the end.

frankenjoe commented 5 months ago

To me having a separate open function seems the cleaner solution. Though there are packages that offer only a close() function, e.g. soundfile. But sounddevice, on the other hand, comes with a start and stop function.

frankenjoe commented 5 months ago

One advantage of a separate open() function could be that you have a factory function that reads the host and repository from some configuration file and returns the backend object. While some other function then takes care of opening and closing the connection.

hagenw commented 5 months ago

Closed by #217