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

Ensure pip-compile --dry-run --quiet still shows what would be done, while omitting the dry run message #1592

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ def write(
) -> None:

for line in self._iter_lines(results, unsafe_requirements, markers, hashes):
log.info(line)
if not self.dry_run:
if self.dry_run:
# Bypass the log level to always print this during a dry run
log.log(line)
else:
log.info(line)
self.dst_file.write(unstyle(line).encode())
self.dst_file.write(os.linesep.encode())

Expand Down
13 changes: 9 additions & 4 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,9 @@ def test_upgrade_packages_version_option_and_upgrade_no_existing_file(pip_conf,
def test_quiet_option(runner):
with open("requirements", "w"):
pass
out = runner.invoke(cli, ["--quiet", "-n", "requirements"])
# Pinned requirements result has not been written to output.
out = runner.invoke(cli, ["--quiet", "requirements"])
# Pinned requirements result has not been written to stdout or stderr:
assert not out.stdout_bytes
assert not out.stderr_bytes


Expand All @@ -818,8 +819,12 @@ def test_dry_run_quiet_option(runner):
with open("requirements", "w"):
pass
out = runner.invoke(cli, ["--dry-run", "--quiet", "requirements"])
# Dry-run message has not been written to output.
assert not out.stderr_bytes
# Neither dry-run message nor pinned requirements written to output:
assert not out.stdout_bytes
# Dry-run message has not been written to stderr:
assert "dry-run" not in out.stderr.lower()
# Pinned requirements (just the header in this case) *are* written to stderr:
assert "# " in out.stderr


def test_generate_hashes_with_editable(pip_conf, runner):
Expand Down