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

handle [[source]] without url - raise PipenvUsageError #3447

Merged
merged 3 commits into from Jan 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2373.bugfix.rst
@@ -0,0 +1 @@
Raise `PipenvUsageError` when [[source]] does not contain url field.
15 changes: 11 additions & 4 deletions pipenv/utils.py
Expand Up @@ -31,6 +31,7 @@
import parse

from . import environments
from .exceptions import PipenvUsageError
AdamGold marked this conversation as resolved.
Show resolved Hide resolved
from .pep508checker import lookup


Expand Down Expand Up @@ -203,20 +204,26 @@ def prepare_pip_source_args(sources, pip_args=None):
pip_args = []
if sources:
# Add the source to notpip.
pip_args.extend(["-i", sources[0]["url"]])
package_url = sources[0].get("url")
if not package_url:
raise PipenvUsageError("[[source]] section does not contain a URL.")
pip_args.extend(["-i", package_url])
# Trust the host if it's not verified.
if not sources[0].get("verify_ssl", True):
pip_args.extend(
["--trusted-host", urllib3_util.parse_url(sources[0]["url"]).host]
["--trusted-host", urllib3_util.parse_url(package_url).host]
)
# Add additional sources as extra indexes.
if len(sources) > 1:
for source in sources[1:]:
pip_args.extend(["--extra-index-url", source["url"]])
url = source.get("url")
if not url: # not harmless, just don't continue
continue
pip_args.extend(["--extra-index-url", url])
# Trust the host if it's not verified.
if not source.get("verify_ssl", True):
pip_args.extend(
["--trusted-host", urllib3_util.parse_url(source["url"]).host]
["--trusted-host", urllib3_util.parse_url(url).host]
)
return pip_args

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_utils.py
Expand Up @@ -8,6 +8,7 @@

import pipenv.utils
import pythonfinder.utils
from pipenv.exceptions import PipenvUsageError


# Pipfile format <-> requirements.txt format.
Expand Down Expand Up @@ -374,6 +375,11 @@ def test_prepare_pip_source_args(self, sources, expected_args):
== expected_args
)

def test_invalid_prepare_pip_source_args(self):
sources = [{}]
with pytest.raises(PipenvUsageError):
pipenv.utils.prepare_pip_source_args(sources, pip_args=None)

@pytest.mark.utils
def test_parse_python_version(self):
ver = pipenv.utils.parse_python_version("Python 3.6.5\n")
Expand Down