@@ -1052,18 +1052,22 @@ def obtain_file_raise_on_failure(self, filename, extension=False, urls=None, dow
10521052 return target_path
10531053 failedpaths .extend (failed_urls )
10541054
1055- # Usual PYPI sources have a format of '<name>-version.ext', with '<name>' has dashes replaced by underscores
1056- if download_filename . count ( '-' ) >= 2 and any ( PYPI_PKG_URL_PATTERN in url for url in source_urls ):
1057- # Last dash is the separator between name and version
1055+ # Usual PYPI sources have a format of '<name>-version.ext'
1056+ # Last dash is the separator between name and version
1057+ if '-' in download_filename :
10581058 dl_name , dl_suffix = download_filename .rsplit ('-' , maxsplit = 1 )
1059+ pypi_like_fn = '-' in dl_name or '.' in dl_name
1060+ else :
1061+ pypi_like_fn = False
1062+ if pypi_like_fn and any (PYPI_PKG_URL_PATTERN in url for url in source_urls ):
10591063 # Guide https://packaging.python.org/en/latest/specifications/binary-distribution-format
10601064 # "any run of -_. characters [...] should be replaced with _".
10611065 # Account for different "compliance levels" and deduplicate (if only dashes were used all are the same)
10621066 alt_download_filenames = nub (f'{ name } -{ dl_suffix } ' for name in (
1063- re .sub ('[.- _]+' , '_' , dl_name ), # Fully compliant
1064- re .sub ('- +' , '_' , dl_name ), # Only dashes
1065- re .sub (r'\. +' , '_' , dl_name ), # Only dots
1066- ))
1067+ re .sub ('[-. _]+' , '_' , dl_name ), # Fully compliant
1068+ re .sub ('[-_] +' , '_' , dl_name ), # Only dashes
1069+ re .sub (r'[\._] +' , '_' , dl_name ), # Only dots
1070+ ) if name != dl_name )
10671071 self .log .warning ("Could not download %s (%s) from any of %s.\n "
10681072 "Retrying with alternative download filenames '%s' as it looks like a PYPI source." ,
10691073 filename , download_filename , ', ' .join (source_urls ), ', ' .join (alt_download_filenames ))
0 commit comments