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

Fix --trusted-host is not copied from *.in to *.txt #964

Merged
merged 3 commits into from
Oct 27, 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
3 changes: 2 additions & 1 deletion piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
UNSAFE_PACKAGES,
create_install_command,
dedup,
get_trusted_hosts,
is_pinned_requirement,
key_from_ireq,
key_from_req,
Expand Down Expand Up @@ -409,7 +410,7 @@ def cli(
generate_hashes=generate_hashes,
default_index_url=repository.DEFAULT_INDEX_URL,
index_urls=repository.finder.index_urls,
trusted_hosts=repository.options.trusted_hosts,
trusted_hosts=get_trusted_hosts(repository.finder),
format_control=repository.finder.format_control,
allow_unsafe=allow_unsafe,
find_links=repository.finder.find_links,
Expand Down
10 changes: 10 additions & 0 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,13 @@ def create_install_command():
from pip._internal.commands import create_command

return create_command("install")


def get_trusted_hosts(finder):
"""
Returns an iterable of trusted hosts from a given finder.
"""
if PIP_VERSION < (19, 2):
return (host for _, host, _ in finder.secure_origins)

return finder.trusted_hosts
atugushev marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,3 +891,30 @@ def test_upgrade_package_doesnt_remove_annotation(pip_conf, runner):
"small-fake-a==0.2 # via small-fake-with-deps-a"
in req_txt.read().splitlines()
)


@pytest.mark.parametrize(
"options",
[
# TODO add --no-index support in OutputWriter
# "--no-index",
"--index-url https://example.com",
"--extra-index-url https://example.com",
"--find-links ./libs1",
"--trusted-host example.com",
"--no-binary :all:",
"--only-binary :all:",
],
)
def test_options_in_requirements_file(runner, options):
"""
Test the options from requirements.in is copied to requirements.txt.
"""
with open("requirements.in", "w") as reqs_in:
reqs_in.write(options)

out = runner.invoke(cli)
assert out.exit_code == 0, out

with open("requirements.txt") as reqs_txt:
assert options in reqs_txt.read().splitlines()
22 changes: 22 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# coding: utf-8
from __future__ import unicode_literals

import itertools
import os

import pytest
import six
from pytest import mark, raises
from six.moves import shlex_quote

from piptools.repositories import PyPIRepository
from piptools.scripts.compile import cli as compile_cli
from piptools.utils import (
as_tuple,
Expand All @@ -19,6 +22,7 @@
fs_str,
get_compile_command,
get_hashes_from_ireq,
get_trusted_hosts,
is_pinned_requirement,
is_url_requirement,
name_from_req,
Expand Down Expand Up @@ -333,3 +337,21 @@ def test_create_install_command():
"""
install_command = create_install_command()
assert install_command.name == "install"


@mark.parametrize(
"hosts",
[
pytest.param((), id="no hosts"),
pytest.param(("example.com",), id="single host"),
pytest.param(("example.com:8080",), id="host with port"),
pytest.param(("example1.com", "example2.com:8080"), id="multiple hosts"),
],
)
def test_get_trusted_hosts(hosts):
"""
Test get_trusted_hosts(finder) returns a list of hosts.
"""
pip_args = list(itertools.chain(*zip(["--trusted-host"] * len(hosts), hosts)))
repository = PyPIRepository(pip_args)
assert tuple(get_trusted_hosts(repository.finder)) == hosts