From 006b4ce889381991fc1df7a17ca6c6c6800504b0 Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Sep 27 2023 19:54:32 +0000 Subject: build_container: display flatpakBuild task with --nowait Like with fedpkg commands, we should provide some feedback that the requested build has been kicked off even if the user chooses --nowait. --- diff --git a/flatpak_module_tools/cli.py b/flatpak_module_tools/cli.py index 9e5b014..23fe3d9 100644 --- a/flatpak_module_tools/cli.py +++ b/flatpak_module_tools/cli.py @@ -248,10 +248,7 @@ def build_container(ctx, task_id = profile.koji_session.flatpakBuild(src, target, opts=opts, priority=priority) - if nowait: - return - - if not watch_koji_task(profile, task_id): + if not watch_koji_task(profile, task_id, nowait=nowait): sys.exit(1) diff --git a/flatpak_module_tools/koji_utils.py b/flatpak_module_tools/koji_utils.py index ff44743..b23915b 100644 --- a/flatpak_module_tools/koji_utils.py +++ b/flatpak_module_tools/koji_utils.py @@ -109,7 +109,7 @@ class WatcherDisplay(LiveDisplay): print(" " + format_task(self.profile, child), file=stream) -def watch_koji_task(profile: ProfileConfig, task_id: int): +def watch_koji_task(profile: ProfileConfig, task_id: int, *, nowait: bool): with WatcherDisplay(profile, task_id) as display: while True: display.query() @@ -118,13 +118,15 @@ def watch_koji_task(profile: ProfileConfig, task_id: int): assert display.task_info state = koji.TASK_STATES[display.task_info['state']] - if state == "FAILED" or state == "CANCELLED" or state == "CLOSED": + if nowait or state == "FAILED" or state == "CANCELLED" or state == "CLOSED": break time.sleep(20) click.echo() - if state == "FAILED": + if nowait: + return True + elif state == "FAILED": error("Build failed") return False elif state == "CANCELLED": diff --git a/tests/test_cli.py b/tests/test_cli.py index 9107729..b74c9ed 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -351,13 +351,11 @@ def test_build_container(watch_koji_task_mock: mock.Mock, if "--skip-tag" in cli_options: opts["skip_tag"] = True priority = 5 if "--background" in cli_options else None + nowait = "--nowait" in cli_options flatpak_build_mock.assert_called_with(src, target, opts=opts, priority=priority) - if "--nowait" in cli_options: - watch_koji_task_mock.assert_not_called() - else: - watch_koji_task_mock.assert_called_with(mock.ANY, 42) + watch_koji_task_mock.assert_called_with(mock.ANY, 42, nowait=nowait) @pytest.mark.usefixtures("fixed_arch")