Closed hagenw closed 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__()
?
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
.
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.
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.
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.
Closed by #217
In https://github.com/audeering/audbackend/pull/204 we introduced
open()
andclose()
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__()
toopen()
. 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 callopen()
, but tries to directly access some file, e.g. withexists()
. Should I raise aaudbackend.BackenError
and state that the backend needs to be first opened?