mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
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
1
news/7430.bugfix
Normal file
1
news/7430.bugfix
Normal file
|
@ -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):
|
def get_formatted_locations(self):
|
||||||
# type: () -> str
|
# type: () -> str
|
||||||
lines = []
|
lines = []
|
||||||
|
redacted_index_urls = []
|
||||||
if self.index_urls and self.index_urls != [PyPI.simple_url]:
|
if self.index_urls and self.index_urls != [PyPI.simple_url]:
|
||||||
lines.append(
|
for url in self.index_urls:
|
||||||
'Looking in indexes: {}'.format(', '.join(
|
|
||||||
redact_auth_from_url(url) 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:
|
if self.find_links:
|
||||||
lines.append(
|
lines.append(
|
||||||
'Looking in links: {}'.format(', '.join(
|
'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)
|
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):
|
def test_install_yanked_file_and_print_warning(script, data):
|
||||||
"""
|
"""
|
||||||
Test install a "yanked" file and print a warning.
|
Test install a "yanked" file and print a warning.
|
||||||
|
|
Loading…
Reference in a new issue