Skip to content

Commit

Permalink
Merge pull request #371 from gtoonstra/master
Browse files Browse the repository at this point in the history
338: Trusted hosts not written to requirements.txt
  • Loading branch information
nvie authored Jun 22, 2016
2 parents 9e5da90 + 091d714 commit f1ea213
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def cli(verbose, dry_run, pre, rebuild, find_links, index_url, extra_index_url,
emit_header=header, emit_index=index,
annotate=annotate,
default_index_url=repository.DEFAULT_INDEX_URL,
index_urls=repository.finder.index_urls, format_control=repository.finder.format_control)
index_urls=repository.finder.index_urls,
trusted_hosts=pip_options.trusted_hosts,
format_control=repository.finder.format_control)
writer.write(results=results,
reverse_dependencies=reverse_dependencies,
primary_packages={ireq.req.key for ireq in constraints})
Expand Down
10 changes: 9 additions & 1 deletion piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class OutputWriter(object):
def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, annotate,
default_index_url, index_urls, format_control):
default_index_url, index_urls, trusted_hosts, format_control):
self.src_files = src_files
self.dst_file = dst_file
self.dry_run = dry_run
Expand All @@ -18,6 +18,7 @@ def __init__(self, src_files, dst_file, dry_run, emit_header, emit_index, annota
self.annotate = annotate
self.default_index_url = default_index_url
self.index_urls = index_urls
self.trusted_hosts = trusted_hosts
self.format_control = format_control

def _sort_key(self, ireq):
Expand Down Expand Up @@ -51,6 +52,11 @@ def write_index_options(self):
if emitted:
yield '' # extra line of whitespace

def write_trusted_hosts(self):
for trusted_host in self.trusted_hosts:
yield '--trusted-host {}'.format(trusted_host)
yield ''

def write_format_controls(self):
for nb in self.format_control.no_binary:
yield '--no-binary {}'.format(nb)
Expand All @@ -63,6 +69,8 @@ def _iter_lines(self, results, reverse_dependencies, primary_packages):
yield line
for line in self.write_index_options():
yield line
for line in self.write_trusted_hosts():
yield line
for line in self.write_format_controls():
yield line

Expand Down
13 changes: 13 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,16 @@ def test_extra_index_option(pip_conf):
' http://example.com\n'
' http://extraindex1.com\n'
' http://extraindex2.com' in out.output)

def test_trusted_host(pip_conf):

assert os.path.exists(pip_conf)

runner = CliRunner()
with runner.isolated_filesystem():
open('requirements.in', 'w').close()
out = runner.invoke(cli, ['-v',
'--trusted-host', 'example2.com'])
print(out.output)
assert ('--trusted-host example.com\n'
'--trusted-host example2.com\n' in out.output)
4 changes: 3 additions & 1 deletion tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
def writer():
return OutputWriter(src_files=["src_file", "src_file2"], dst_file="dst_file", dry_run=True,
emit_header=True, emit_index=True, annotate=True,
default_index_url=None, index_urls=[], format_control=FormatControl(set(), set()))
default_index_url=None, index_urls=[],
trusted_hosts=[],
format_control=FormatControl(set(), set()))


def test_format_requirement_annotation_editable(from_editable, writer):
Expand Down

0 comments on commit f1ea213

Please sign in to comment.