Skip to content

Commit

Permalink
Ensure 'pip-compile --dry-run --quiet' logs the resulting content
Browse files Browse the repository at this point in the history
- content to stderr
- omit the dry run message

Fixes #845
  • Loading branch information
AndydeCleyre committed Apr 4, 2022
1 parent 24ebb83 commit 5f22bb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 5f22bb3

Please sign in to comment.