Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sync to return non-zero exit code on dry run #1172

Merged
merged 6 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == 2
atugushev marked this conversation as resolved.
Show resolved Hide resolved


@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