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

no straightforward way to call pip-compile without writing to a file #275

Closed
cjerdonek opened this issue Dec 21, 2015 · 8 comments
Closed

Comments

@cjerdonek
Copy link

For scripting purposes, it would be nice to have a straightforward way to call pip-compile that writes only to stdout, and not to a file.

A --no-output-file option seems like the most straightforward approach given the other --no-* options.

Some observations:

  1. Passing --dry-run seems like the only way, but the option isn't intuitively named since this would be a "real run" for the use case I described.
  2. Passing --dry-run also gives the warning "Dry-run, so nothing updated." It would be nice if no warning was emitted for the use case I described.
  3. Passing --dry-run with multiple *.in files still gives the error "Error: Invalid value: --output-file is required if two or more input files are given."
  4. As an alternative to passing --dry-run, passing --output-file /dev/null when using subprocess.Popen gives the following error.

Error:

Traceback (most recent call last):
  File "/Users/chris/dev/bin/pip-compile", line 11, in <module>
    sys.exit(cli())
  File "/Users/chris/dev/lib/python3.5/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/chris/dev/lib/python3.5/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/chris/dev/lib/python3.5/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/chris/dev/lib/python3.5/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/chris/dev/lib/python3.5/site-packages/piptools/scripts/compile.py", line 183, in cli
    primary_packages={ireq.req.key for ireq in constraints})
  File "/Users/chris/dev/lib/python3.5/site-packages/piptools/writer.py", line 82, in write
    f = stack.enter_context(AtomicSaver(self.dst_file))
  File "/Users/chris_g4/.pyenv/versions/3.5.1/lib/python3.5/contextlib.py", line 304, in enter_context
    result = _cm_type.__enter__(cm)
  File "/Users/chris/dev/lib/python3.5/site-packages/piptools/io.py", line 181, in __enter__
    self.setup()
  File "/Users/chris/dev/lib/python3.5/site-packages/piptools/io.py", line 177, in setup
    self._open_part_file()
  File "/Users/chris/dev/lib/python3.5/site-packages/piptools/io.py", line 142, in _open_part_file
    fd = os.open(self.part_path, self.open_flags, file_perms)
PermissionError: [Errno 13] Permission denied: '/dev/null.part'
@nvie
Copy link
Member

nvie commented Dec 21, 2015

Correct, we're not doing a great job here yet. PR #265 already brought - handling for input arguments, but we definitely need to do the same for outputs. I'd like to follow the Unix convention of using '-' as the "filename" to specify stdout, i.e.:

$ pip-compile --output-file -

Should read requirements.in, and write its output to stdout.

@cjerdonek
Copy link
Author

Sounds good, thanks!

@tysonclugg
Copy link
Contributor

This now works if you specify the output file as -.

@cjerdonek
Copy link
Author

cjerdonek commented May 2, 2018 via email

@cjerdonek
Copy link
Author

cjerdonek commented May 2, 2018

FYI, I just checked, and I don't see any evidence in the code this functionality was ever added. I also tried running with -o - using version 2.0.1, and it created a file with name -. So it looks like this issue shouldn't be closed.

@tysonclugg
Copy link
Contributor

Apologies, reopened!

@georgek
Copy link
Contributor

georgek commented Jun 7, 2019

The click library automatically treats "-" as stdout, so this works, kind of. The problem is that pip-compile also prints its output on standard output regardless, so you get each line duplicated.

Personally I don't like command line tools printing to standard output as a side effect. Standard output should always be the default output of any command line program (if possible). In fact, output files are only necessary if more than one output is required (otherwise the user can just redirect stdout himself).

if some kind of "pretty" output is required then stderr can be used instead.

I could go ahead and make these changes to bring this tool more in line with standard command line utilities, but unfortunately this will break existing code that depends on the unfortunate current behaviour of implicitly writing to requirements.txt, for example.

Are the authors prepared to break the current CLI and issue a new major version?

@atugushev
Copy link
Member

It works echo django | pip-compile - -qo-.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants