Skip to content

Commit

Permalink
Update sync to return non-zero exit code on dry run (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
francisbrito authored Jul 22, 2020
1 parent 9eb10d7 commit bd3e735
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 7 additions & 2 deletions piptools/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -181,8 +183,11 @@ def sync(
for ireq in sorted(to_install, key=key_from_ireq):
click.echo(" {}".format(format_requirement(ireq)))

exit_code = 1

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:
Expand Down Expand Up @@ -215,4 +220,4 @@ def sync(
finally:
os.unlink(tmp_req_file.name)

return 0
return exit_code
14 changes: 13 additions & 1 deletion tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 1


@pytest.mark.parametrize(
Expand Down Expand Up @@ -231,3 +231,15 @@ def test_sync_ask_accepted(check_call, runner):
runner.invoke(cli, ["--ask", "--dry-run"], input="y\n")

assert check_call.call_count == 2


def test_sync_dry_run_returns_non_zero_exit_code(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 == 1

0 comments on commit bd3e735

Please sign in to comment.