Skip to content

Commit

Permalink
Merge pull request #5819 from uranusjr/htmlpage-clean
Browse files Browse the repository at this point in the history
HTMLPage cleanup and egg_info_matches fix
  • Loading branch information
dstufft authored Sep 27, 2018
2 parents 98338dc + 9d1c2db commit f4a41a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions news/5819.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect parsing of egg names if pip needs to guess the package name.
1 change: 1 addition & 0 deletions news/5819.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify always-true conditions in ``HTMLPage.get_page()``.
33 changes: 16 additions & 17 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def egg_info_matches(
return None
if search_name is None:
full_match = match.group(0)
return full_match[full_match.index('-'):]
return full_match.split('-', 1)[-1]
name = match.group(0).lower()
# To match the "safe" name that pkg_resources creates:
name = name.replace('_', '-')
Expand Down Expand Up @@ -731,7 +731,7 @@ def __str__(self):
return self.url

@classmethod
def get_page(cls, link, skip_archives=True, session=None):
def get_page(cls, link, session=None):
if session is None:
raise TypeError(
"get_page() missing 1 required keyword argument: 'session'"
Expand All @@ -748,22 +748,21 @@ def get_page(cls, link, skip_archives=True, session=None):
return None

try:
if skip_archives:
filename = link.filename
for bad_ext in ARCHIVE_EXTENSIONS:
if filename.endswith(bad_ext):
content_type = cls._get_content_type(
url, session=session,
filename = link.filename
for bad_ext in ARCHIVE_EXTENSIONS:
if filename.endswith(bad_ext):
content_type = cls._get_content_type(
url, session=session,
)
if content_type.lower().startswith('text/html'):
break
else:
logger.debug(
'Skipping page %s because of Content-Type: %s',
link,
content_type,
)
if content_type.lower().startswith('text/html'):
break
else:
logger.debug(
'Skipping page %s because of Content-Type: %s',
link,
content_type,
)
return
return

logger.debug('Getting page %s', url)

Expand Down

0 comments on commit f4a41a2

Please sign in to comment.