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

Remove unnecessary envvar configuration in click options #1238

Merged
merged 1 commit into from
Nov 25, 2020
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
10 changes: 1 addition & 9 deletions piptools/scripts/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,16 @@ def has_arg(self, arg_name):
"--find-links",
multiple=True,
help="Look for archives in this directory or on this HTML page",
envvar="PIP_FIND_LINKS",
)
@click.option(
"-i",
"--index-url",
help="Change index URL (defaults to {index_url})".format(
index_url=redact_auth_from_url(_get_default_option("index_url"))
),
envvar="PIP_INDEX_URL",
)
@click.option(
"--extra-index-url",
multiple=True,
help="Add additional index URL to search",
envvar="PIP_EXTRA_INDEX_URL",
"--extra-index-url", multiple=True, help="Add additional index URL to search"
)
@click.option("--cert", help="Path to alternate CA bundle.")
@click.option(
Expand All @@ -115,7 +110,6 @@ def has_arg(self, arg_name):
@click.option(
"--trusted-host",
multiple=True,
envvar="PIP_TRUSTED_HOST",
help="Mark this host as trusted, even though it does not have "
"valid or any HTTPS.",
)
Expand Down Expand Up @@ -216,9 +210,7 @@ def has_arg(self, arg_name):
"--cache-dir",
help="Store the cache data in DIRECTORY.",
default=CACHE_DIR,
envvar="PIP_TOOLS_CACHE_DIR",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show_default=True,
show_envvar=True,
type=click.Path(file_okay=False, writable=True),
)
@click.option("--pip-args", help="Arguments to pass directly to the pip command.")
Expand Down
13 changes: 2 additions & 11 deletions piptools/scripts/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@
"--find-links",
multiple=True,
help="Look for archives in this directory or on this HTML page",
envvar="PIP_FIND_LINKS",
)
@click.option("-i", "--index-url", help="Change index URL (defaults to PyPI)")
@click.option(
"-i",
"--index-url",
help="Change index URL (defaults to PyPI)",
envvar="PIP_INDEX_URL",
)
@click.option(
"--extra-index-url",
multiple=True,
help="Add additional index URL to search",
envvar="PIP_EXTRA_INDEX_URL",
"--extra-index-url", multiple=True, help="Add additional index URL to search"
)
@click.option(
"--trusted-host",
Expand Down
50 changes: 49 additions & 1 deletion tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ def test_find_links_option(runner):
)


def test_find_links_envvar(monkeypatch, runner):
with open("requirements.in", "w") as req_in:
req_in.write("-f ./libs3")

monkeypatch.setenv("PIP_FIND_LINKS", "./libs1 ./libs2")
out = runner.invoke(cli, ["-v"])

# Check that find-links has been passed to pip
assert "Using links:\n ./libs1\n ./libs2\n ./libs3\n" in out.stderr

# Check that find-links has been written to a requirements.txt
with open("requirements.txt", "r") as req_txt:
assert (
"--find-links ./libs1\n--find-links ./libs2\n--find-links ./libs3\n"
in req_txt.read()
)


def test_extra_index_option(pip_with_index_conf, runner):
with open("requirements.in", "w"):
pass
Expand All @@ -144,6 +162,28 @@ def test_extra_index_option(pip_with_index_conf, runner):
)


def test_extra_index_envvar(monkeypatch, runner):
with open("requirements.in", "w"):
pass

monkeypatch.setenv("PIP_INDEX_URL", "http://example.com")
monkeypatch.setenv(
"PIP_EXTRA_INDEX_URL", "http://extraindex1.com http://extraindex2.com"
)
out = runner.invoke(cli, ["-v"])
assert (
"Using indexes:\n"
" http://example.com\n"
" http://extraindex1.com\n"
" http://extraindex2.com" in out.stderr
)
assert (
"--index-url http://example.com\n"
"--extra-index-url http://extraindex1.com\n"
"--extra-index-url http://extraindex2.com" in out.stderr
)


@pytest.mark.parametrize("option", ("--extra-index-url", "--find-links"))
def test_redacted_urls_in_verbose_output(runner, option):
"""
Expand All @@ -168,7 +208,7 @@ def test_redacted_urls_in_verbose_output(runner, option):
assert "password" not in out.stderr


def test_trusted_host(pip_conf, runner):
def test_trusted_host_option(pip_conf, runner):
with open("requirements.in", "w"):
pass
out = runner.invoke(
Expand All @@ -177,6 +217,14 @@ def test_trusted_host(pip_conf, runner):
assert "--trusted-host example.com\n--trusted-host example2.com\n" in out.stderr


def test_trusted_host_envvar(monkeypatch, pip_conf, runner):
with open("requirements.in", "w"):
pass
monkeypatch.setenv("PIP_TRUSTED_HOST", "example.com example2.com")
out = runner.invoke(cli, ["-v"])
assert "--trusted-host example.com\n--trusted-host example2.com\n" in out.stderr


@pytest.mark.parametrize(
"options",
(
Expand Down