@@ -336,24 +336,23 @@ def poetry_based?
336336
337337 sig { returns ( T ::Boolean ) }
338338 def library?
339- return false unless updating_pyproject?
340- return false unless library_details
339+ return @is_library unless @is_library . nil?
341340
342- return false if T . must ( library_details ) [ "name" ] . nil?
341+ @is_library = T . let ( check_pypi_for_library_match , T . nilable ( T ::Boolean ) )
342+ @is_library || false
343+ end
344+
345+ sig { returns ( T ::Boolean ) }
346+ def check_pypi_for_library_match
347+ return false unless updating_pyproject? && library_details && !T . must ( library_details ) [ "name" ] . nil?
343348
344- # Hit PyPi and check whether there are details for a library with a
345- # matching name and description
346- index_response = Dependabot ::RegistryClient . get (
349+ response = Dependabot ::RegistryClient . get (
347350 url : "https://pypi.org/pypi/#{ normalised_name ( T . must ( library_details ) [ 'name' ] ) } /json/"
348351 )
352+ return false unless response . status == 200
349353
350- return false unless index_response . status == 200
351-
352- pypi_info = JSON . parse ( index_response . body ) [ "info" ] || { }
353- pypi_info [ "summary" ] == T . must ( library_details ) [ "description" ]
354- rescue Excon ::Error ::Timeout , Excon ::Error ::Socket
355- false
356- rescue URI ::InvalidURIError
354+ ( JSON . parse ( response . body ) [ "info" ] || { } ) [ "summary" ] == T . must ( library_details ) [ "description" ]
355+ rescue Excon ::Error ::Timeout , Excon ::Error ::Socket , URI ::InvalidURIError
357356 false
358357 end
359358
0 commit comments