Skip to content

Commit

Permalink
Merge pull request #733 from atugushev/emit-orig-cmd
Browse files Browse the repository at this point in the history
Emit to the pip-compile's header an original command
  • Loading branch information
vphilippon authored Feb 14, 2019
2 parents 9976139 + 7d12a5d commit 200bc6b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
20 changes: 5 additions & 15 deletions piptools/writer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import sys
from itertools import chain

from ._compat import ExitStack
from .click import unstyle
from .click import unstyle, get_os_args
from .io import AtomicSaver
from .logging import log
from .utils import comment, dedup, format_requirement, key_from_req, UNSAFE_PACKAGES
Expand Down Expand Up @@ -40,20 +41,9 @@ def write_header(self):
if custom_cmd:
yield comment('# {}'.format(custom_cmd))
else:
params = []
if not self.emit_index:
params += ['--no-index']
if not self.emit_trusted_host:
params += ['--no-emit-trusted-host']
if not self.annotate:
params += ['--no-annotate']
if self.generate_hashes:
params += ["--generate-hashes"]
if self.allow_unsafe:
params += ["--allow-unsafe"]
params += ['--output-file', self.dst_file]
params += self.src_files
yield comment('# pip-compile {}'.format(' '.join(params)))
prog = os.path.basename(sys.argv[0])
args = ' '.join(get_os_args())
yield comment('# {prog} {args}'.format(prog=prog, args=args))
yield comment('#')

def write_index_options(self):
Expand Down
12 changes: 2 additions & 10 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def test_trusted_host_no_emit(pip_conf):
'--trusted-host', 'example.com',
'--no-emit-trusted-host'])
assert '--trusted-host example.com' not in out.output
assert '--no-emit-trusted-host' in out.output


def test_realistic_complex_sub_dependencies(tmpdir):
Expand Down Expand Up @@ -306,11 +305,11 @@ def test_input_file_without_extension(tmpdir):
with open('requirements', 'w') as req_in:
req_in.write('six==1.10.0')

out = runner.invoke(cli, ['-n', 'requirements'])
out = runner.invoke(cli, ['requirements'])

assert out.exit_code == 0
assert '--output-file requirements.txt' in out.output
assert 'six==1.10.0' in out.output
assert os.path.exists('requirements.txt')


def test_upgrade_packages_option(tmpdir):
Expand Down Expand Up @@ -383,12 +382,6 @@ def test_generate_hashes_with_editable():
],
)
expected = (
'#\n'
'# This file is autogenerated by pip-compile\n'
'# To update, run:\n'
'#\n'
'# pip-compile --generate-hashes --output-file requirements.txt requirements.in\n'
'#\n'
'-e {}\n'
'pytz==2017.2 \\\n'
' --hash=sha256:d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67 \\\n'
Expand All @@ -413,7 +406,6 @@ def test_filter_pip_markes():
out = runner.invoke(cli, ['-n', 'requirements'])

assert out.exit_code == 0
assert '--output-file requirements.txt' in out.output
assert 'six==1.10.0' in out.output
assert 'unknown_package' not in out.output

Expand Down
28 changes: 26 additions & 2 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,33 @@ def test_iter_lines__unsafe_dependencies(from_line, allow_unsafe):
))
assert comment('# The following packages are considered to be unsafe in a requirements file:') in str_lines
if allow_unsafe:
assert comment('# pip-compile --allow-unsafe --output-file dst_file src_file src_file2') in str_lines
assert 'setuptools' in str_lines
else:
assert comment('# pip-compile --output-file dst_file src_file src_file2') in str_lines
assert comment('# setuptools') in str_lines
assert 'test==1.2' in str_lines


def test_write_header(writer, monkeypatch):
monkeypatch.setattr("sys.argv", ['pip-compile', '--output-file', 'dst_file', 'src_file', 'src_file2'])
expected = map(comment, [
'#',
'# This file is autogenerated by pip-compile',
'# To update, run:',
'#',
'# pip-compile --output-file dst_file src_file src_file2',
'#',
])
assert list(writer.write_header()) == list(expected)


def test_write_header_custom_compile_command(writer, monkeypatch):
monkeypatch.setenv('CUSTOM_COMPILE_COMMAND', './pipcompilewrapper')
expected = map(comment, [
'#',
'# This file is autogenerated by pip-compile',
'# To update, run:',
'#',
'# ./pipcompilewrapper',
'#',
])
assert list(writer.write_header()) == list(expected)

0 comments on commit 200bc6b

Please sign in to comment.