def run()

in aws_lambda_builders/workflows/ruby_bundler/bundler.py [0:0]


    def run(self, args, cwd=None):
        if not isinstance(args, list):
            raise ValueError("args must be a list")

        if not args:
            raise ValueError("requires at least one arg")

        invoke_bundler = [self.bundler_exe] + args

        LOG.debug("executing Bundler: %s", invoke_bundler)

        p = self.osutils.popen(invoke_bundler, stdout=self.osutils.pipe, stderr=self.osutils.pipe, cwd=cwd)

        out, err = p.communicate()

        if p.returncode != 0:
            if p.returncode == GEMFILE_NOT_FOUND:
                LOG.warning("Gemfile not found. Continuing the build without dependencies.")

                # Clean up '.bundle' dir that gets generated before the build fails
                check_dir = self.osutils.get_bundle_dir(cwd)
                if self.osutils.directory_exists(check_dir):
                    self.osutils.remove_directory(check_dir)
            else:
                # Bundler can contain information in both stdout and stderr so we check and log both
                err_str = err.decode("utf8").strip()
                out_str = out.decode("utf8").strip()
                if out_str and err_str:
                    message_out = f"{out_str}{linesep}{err_str}"
                    LOG.debug(f"Bundler output: {out_str}")
                    LOG.debug(f"Bundler error: {err_str}")
                elif out_str:
                    message_out = out_str
                    LOG.debug(f"Bundler output: {out_str}")
                else:
                    message_out = err_str
                    LOG.debug(f"Bundler error: {err_str}")
                raise BundlerExecutionError(message=message_out)

        return out.decode("utf8").strip()