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

Emit to the pip-compile's header an original command #733

Merged
merged 1 commit into from
Feb 14, 2019
Merged
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
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'
atugushev marked this conversation as resolved.
Show resolved Hide resolved
'-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)