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

Improve pip-compile with regard to stdout #361

Closed
wants to merge 5 commits into from
Closed
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
4 changes: 3 additions & 1 deletion piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,

if len(src_files) == 1 and src_files[0] == '-':
if not output_file:
raise click.BadParameter('--output-file is required if input is from stdin')
output_file = '-'
if output_file == '-':
header = False

if len(src_files) > 1 and not output_file:
raise click.BadParameter('--output-file is required if two or more input files are given.')
Expand Down
16 changes: 9 additions & 7 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ def write_index_options(self):
yield '' # extra line of whitespace

def write_format_controls(self):
for nb in self.format_control.no_binary:
yield '--no-binary {}'.format(nb)
for ob in self.format_control.only_binary:
yield '--only-binary {}'.format(ob)
yield ''
if self.format_control.no_binary or self.format_control.only_binary:
for nb in self.format_control.no_binary:
yield '--no-binary {}'.format(nb)
for ob in self.format_control.only_binary:
yield '--only-binary {}'.format(ob)
yield ''

def _iter_lines(self, results, reverse_dependencies, primary_packages):
for line in self.write_header():
Expand Down Expand Up @@ -89,14 +90,15 @@ def _iter_lines(self, results, reverse_dependencies, primary_packages):
def write(self, results, reverse_dependencies, primary_packages):
with ExitStack() as stack:
f = None
if not self.dry_run:
if not self.dry_run and self.dst_file != '-':
f = stack.enter_context(AtomicSaver(self.dst_file))

for line in self._iter_lines(results, reverse_dependencies, primary_packages):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing logging, shouldn't the log be going to stderr like most logging does? If it goes to stderr, it wouldn't be interfering with the stdout issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjerdonek

shouldn't the log be going to stderr like most logging does?

Agreed. Do you want to create an issue for it?
But then this log line is still a bit too verbose (move it to debug? / add a prefix like "writing line"?).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can make an issue. (I would need to confirm first that log does indeed go to stdout.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here: #362

log.info(line)
if f:
f.write(unstyle(line).encode('utf-8'))
f.write(os.linesep.encode('utf-8'))
else:
print(line)

def _format_requirement(self, ireq, reverse_dependencies, primary_packages, include_specifier=True):
line = format_requirement(ireq, include_specifier=include_specifier)
Expand Down