Warn if an invalid URL is passed with --index-url

This commit is contained in:
Devesh Kumar Singh 2020-04-03 00:08:32 +05:30
parent 6086f71cde
commit 4c70c6d350
2 changed files with 23 additions and 4 deletions

1
news/7430.bugfix Normal file
View File

@ -0,0 +1 @@
Warn if an invalid URL is passed with --index-url

View File

@ -77,11 +77,29 @@ 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 netlock 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('index-url {} is invalid.'.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(