From a2ed554f98ad1527dc25d96074deecd5eaf1ef0c Mon Sep 17 00:00:00 2001 From: Francis Brito Date: Fri, 3 Jul 2020 04:02:01 -0400 Subject: [PATCH 1/5] Update sync to return non-zero exit code on dry run Relates to #1166 --- piptools/sync.py | 9 +++++++-- tests/test_cli_sync.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/piptools/sync.py b/piptools/sync.py index 34bd4da4d..18218b9cc 100644 --- a/piptools/sync.py +++ b/piptools/sync.py @@ -158,10 +158,12 @@ def sync( """ Install and uninstalls the given sets of modules. """ + exit_code = 0 + if not to_uninstall and not to_install: if verbose: click.echo("Everything up-to-date") - return 0 + return exit_code pip_flags = [] if not verbose: @@ -181,8 +183,11 @@ def sync( for ireq in sorted(to_install, key=key_from_ireq): click.echo(" {}".format(format_requirement(ireq))) + exit_code = 2 + if ask and click.confirm("Would you like to proceed with these changes?"): dry_run = False + exit_code = 0 if not dry_run: if to_uninstall: @@ -215,4 +220,4 @@ def sync( finally: os.unlink(tmp_req_file.name) - return 0 + return exit_code diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index 22cf6f0c1..86df0134d 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -120,7 +120,7 @@ def test_merge_error(req_lines, should_raise, runner): assert out.exit_code == 2 assert "Incompatible requirements found" in out.stderr else: - assert out.exit_code == 0 + assert out.exit_code == 2 @pytest.mark.parametrize( @@ -231,3 +231,16 @@ def test_sync_ask_accepted(check_call, runner): runner.invoke(cli, ["--ask", "--dry-run"], input="y\n") assert check_call.call_count == 2 + + +@mock.patch("piptools.sync.check_call") +def test_sync_dry_run_returns_non_zero_exit_code(check_call, runner): + """ + Make sure non-zero exit code is returned when --dry-run is given. + """ + with open("requirements.txt", "w") as req_in: + req_in.write("small-fake-a==1.10.0") + + out = runner.invoke(cli, ["--dry-run"]) + + assert out.exit_code == 2 From 24309cb496c530fd9af74bd8ca041ea0bf513023 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 20 Jul 2020 18:32:54 +0700 Subject: [PATCH 2/5] Address review comments No need for `check_call` --- tests/test_cli_sync.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index 86df0134d..50eb21171 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -233,8 +233,7 @@ def test_sync_ask_accepted(check_call, runner): assert check_call.call_count == 2 -@mock.patch("piptools.sync.check_call") -def test_sync_dry_run_returns_non_zero_exit_code(check_call, runner): +def test_sync_dry_run_returns_non_zero_exit_code(runner): """ Make sure non-zero exit code is returned when --dry-run is given. """ From 3a1dbff15c1f0fd085abbf6698fcee849ccdae3d Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 20 Jul 2020 18:34:42 +0700 Subject: [PATCH 3/5] Address review comments Exit with code 1 --- piptools/sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/piptools/sync.py b/piptools/sync.py index 18218b9cc..4e2bb4940 100644 --- a/piptools/sync.py +++ b/piptools/sync.py @@ -183,7 +183,7 @@ def sync( for ireq in sorted(to_install, key=key_from_ireq): click.echo(" {}".format(format_requirement(ireq))) - exit_code = 2 + exit_code = 1 if ask and click.confirm("Would you like to proceed with these changes?"): dry_run = False From b3b2d889035aab364d071bac379c4c2550b65732 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 20 Jul 2020 18:35:32 +0700 Subject: [PATCH 4/5] Address review comments Exit with code 1 --- tests/test_cli_sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index 50eb21171..60e32222e 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -242,4 +242,4 @@ def test_sync_dry_run_returns_non_zero_exit_code(runner): out = runner.invoke(cli, ["--dry-run"]) - assert out.exit_code == 2 + assert out.exit_code == 1 From 4167b27e11dad263e1a02cadf7b50e276bbe485e Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Mon, 20 Jul 2020 19:13:24 +0700 Subject: [PATCH 5/5] Address review comments Exit with code 1 --- tests/test_cli_sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli_sync.py b/tests/test_cli_sync.py index 60e32222e..1db8cc56d 100644 --- a/tests/test_cli_sync.py +++ b/tests/test_cli_sync.py @@ -120,7 +120,7 @@ def test_merge_error(req_lines, should_raise, runner): assert out.exit_code == 2 assert "Incompatible requirements found" in out.stderr else: - assert out.exit_code == 2 + assert out.exit_code == 1 @pytest.mark.parametrize(