gabrieldemarmiesse / python-on-whales

An awesome Python wrapper for an awesome Docker CLI!
MIT License
561 stars 102 forks source link

No method to try to pull an image, while handling gracefully #649

Open gabriel-st-angel-aerospace opened 5 hours ago

gabriel-st-angel-aerospace commented 5 hours ago

First off I just wanted to express my gratitude for this library and all of the work that has gone into it. It's been very helpful for my project and is much cleaner than docker-py.

I am trying to write some logic to see if an image exists locally, then attempt to pull it if it doesn't, while handling everything gracefully.

docker.image.inspect() is great for checking if an image exists locally, proper error handling and doesn't muddy up stdout.

However, docker.pull() doesn't try to catch any exceptions and spits out some junk to stdout.

I propose a try/catch around docker.pull that raises a NoSuchImage if the pull fails.

gabrieldemarmiesse commented 2 hours ago

First of all, many thanks for the kind words, those are what keep the maintainers going!

Second, that would be a great addition to python-on-whales to have specific exceptions in docker.pull() depending on the reasons for failure. We can get the information from stderr or from the exit code (if the exit code differs depending on the reason for failing). I'm open for pull requests in this direction as long as it doesn't complexify the codebase too much!