Got a MacOS app I am working on and I need to know if Docker is running or not and start it if it is not. Given I didn't see any docker-client packages for Swift I was going to use PythonKit to interact with Docker.
Doing this and everything is fine, as long as docker is already running. If you try to access docker via pythonkit when docker is not running PythonKit throws an exception but trying to catch it via Swift hasn't worked for me.
Example:
do {
let client = try? dckr.from_env()
}
catch {
print("docker still not ready")
}
Result:
Fatal error: 'try!' expression unexpectedly raised an error: Python exception: Error while fetching server API version: ('Connection aborted.', ConnectionRefusedError(61, 'Connection refused'))
Huh. It seems they didn't add @dynamicCallable to ThrowingPythonObject because "the syntax is unintuitive", but didn't change the method names. Oh well...
You will have to manually call the necessary method:
let client = try dckr.from_env.throwing.dynamicallyCall(withArguments: [])