mirror of https://github.com/pypa/pip
Merge pull request #7965 from deveshks/warn-on-invalid-index-url
Warn if an invalid URL is passed with --index-url
This commit is contained in:
commit
ea1295b720
|
@ -0,0 +1 @@
|
|||
Warn if an invalid URL is passed with --index-url
|
|
@ -77,11 +77,30 @@ class SearchScope(object):
|
|||
def get_formatted_locations(self):
|
||||
# type: () -> str
|
||||
lines = []
|
||||
redacted_index_urls = []
|
||||
if self.index_urls and self.index_urls != [PyPI.simple_url]:
|
||||
lines.append(
|
||||
'Looking in indexes: {}'.format(', '.join(
|
||||
redact_auth_from_url(url) for url in self.index_urls))
|
||||
)
|
||||
for url in self.index_urls:
|
||||
|
||||
redacted_index_url = redact_auth_from_url(url)
|
||||
|
||||
# Parse the URL
|
||||
purl = urllib_parse.urlsplit(redacted_index_url)
|
||||
|
||||
# URL is generally invalid if scheme and netloc is missing
|
||||
# there are issues with Python and URL parsing, so this test
|
||||
# is a bit crude. See bpo-20271, bpo-23505. Python doesn't
|
||||
# always parse invalid URLs correctly - it should raise
|
||||
# exceptions for malformed URLs
|
||||
if not purl.scheme and not purl.netloc:
|
||||
logger.warning(
|
||||
'The index url "{}" seems invalid, '
|
||||
'please provide a scheme.'.format(redacted_index_url))
|
||||
|
||||
redacted_index_urls.append(redacted_index_url)
|
||||
|
||||
lines.append('Looking in indexes: {}'.format(
|
||||
', '.join(redacted_index_urls)))
|
||||
|
||||
if self.find_links:
|
||||
lines.append(
|
||||
'Looking in links: {}'.format(', '.join(
|
||||
|
|
|
@ -1769,6 +1769,31 @@ def test_ignore_yanked_file(script, data):
|
|||
assert 'Successfully installed simple-2.0\n' in result.stdout, str(result)
|
||||
|
||||
|
||||
def test_invalid_index_url_argument(script, shared_data):
|
||||
"""
|
||||
Test the behaviour of an invalid --index-url argument
|
||||
"""
|
||||
|
||||
result = script.pip('install', '--index-url', '--user',
|
||||
shared_data.find_links3, "Dinner",
|
||||
expect_error=True)
|
||||
|
||||
assert 'WARNING: The index url "--user" seems invalid, ' \
|
||||
'please provide a scheme.' in result.stderr, str(result)
|
||||
|
||||
|
||||
def test_valid_index_url_argument(script, shared_data):
|
||||
"""
|
||||
Test the behaviour of an valid --index-url argument
|
||||
"""
|
||||
|
||||
result = script.pip('install', '--index-url',
|
||||
shared_data.find_links3,
|
||||
"Dinner")
|
||||
|
||||
assert 'Successfully installed Dinner' in result.stdout, str(result)
|
||||
|
||||
|
||||
def test_install_yanked_file_and_print_warning(script, data):
|
||||
"""
|
||||
Test install a "yanked" file and print a warning.
|
||||
|
|
Loading…
Reference in New Issue