diff --git a/piptools/writer.py b/piptools/writer.py index 68c0c3bdf..9ac97792f 100644 --- a/piptools/writer.py +++ b/piptools/writer.py @@ -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 @@ -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): diff --git a/tests/test_cli.py b/tests/test_cli.py index 3c4229dd8..1b6ec2959 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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): @@ -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): @@ -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' @@ -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 diff --git a/tests/test_writer.py b/tests/test_writer.py index b3b3773e9..cfec3fb5d 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -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)