From ec02a05e52ce73c30c485bd8b726d5aaab0cbe49 Mon Sep 17 00:00:00 2001 From: gw Date: Mon, 23 Sep 2024 20:00:31 +0100 Subject: [PATCH] Fix return type issues from PR feedback Signed-off-by: gw --- plugins/modules/podman_image.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/modules/podman_image.py b/plugins/modules/podman_image.py index c2c60626..79d14169 100644 --- a/plugins/modules/podman_image.py +++ b/plugins/modules/podman_image.py @@ -495,10 +495,10 @@ def _get_id_from_output(self, lines, startswith=None, contains=None, split_on=' def _find_containerfile_from_context(self): """ Find a Containerfile/Dockerfile path inside a podman build context. - Return an empty string if none exist. + Return 'None' if none exist. """ - containerfile_path = "" + containerfile_path = None for filename in [os.path.join(self.path, fname) for fname in ["Containerfile", "Dockerfile"]]: if os.path.exists(filename): containerfile_path = filename @@ -512,13 +512,16 @@ def _get_containerfile_contents(self): See if either `file` or `container_file` in build args are populated, fetch their contents if so. If not, return the contents of the Containerfile - or Dockerfile from inside the build context. + or Dockerfile from inside the build context, if present. + + If we don't find a Containerfile/Dockerfile in any of the above + locations, return 'None'. """ build_file_arg = self.build.get('file') if self.build else None containerfile_contents = self.build.get('container_file') if self.build else None - container_filename = "" + container_filename = None if build_file_arg: container_filename = build_file_arg elif self.path and not build_file_arg: @@ -550,7 +553,7 @@ def _get_args_containerfile_hash(self): args_containerfile_hash = "" - context_has_containerfile = self.path and self._find_containerfile_from_context() != "" + context_has_containerfile = self.path and self._find_containerfile_from_context() should_hash_args_containerfile = ( context_has_containerfile or @@ -783,7 +786,7 @@ def build_image(self, containerfile_hash): f.write(container_file_txt) args.extend(['--file', container_file_path]) - if containerfile_hash != "": + if containerfile_hash: args.extend(['--label', f"containerfile.hash={containerfile_hash}"]) volume = self.build.get('volume')