@@ -190,6 +190,28 @@ def get_download_location_for_go(link):
190190 return ret , new_link
191191
192192
193+ def get_available_wheel_urls (name , version ):
194+ try :
195+ api_url = f'https://pypi.org/pypi/{ name } /{ version } /json'
196+ response = requests .get (api_url )
197+ if response .status_code == 200 :
198+ data = response .json ()
199+ wheel_urls = []
200+
201+ for file_info in data .get ('urls' , []):
202+ if file_info .get ('packagetype' ) == 'bdist_wheel' :
203+ wheel_urls .append (file_info .get ('url' ))
204+
205+ return wheel_urls
206+ else :
207+ logger .warning (f'Cannot get PyPI API data for { name } ({ version } )' )
208+ return []
209+
210+ except Exception as error :
211+ logger .warning (f'Failed to get wheel URLs from PyPI API: { error } ' )
212+ return []
213+
214+
193215def get_download_location_for_pypi (link ):
194216 # get the url for downloading source file: https://docs.pypi.org/api/ Predictable URLs
195217 ret = False
@@ -202,24 +224,56 @@ def get_download_location_for_pypi(link):
202224 oss_name = re .sub (r"[-_.]+" , "-" , oss_name )
203225 oss_version = dn_loc_re [0 ][1 ]
204226
227+ # 1. Source distribution 시도
205228 new_link = f'{ host } /packages/source/{ oss_name [0 ]} /{ oss_name } /{ oss_name } -{ oss_version } .tar.gz'
206229 try :
207230 res = urlopen (new_link )
208231 if res .getcode () == 200 :
209232 ret = True
210- else :
211- logger .warning (f'Cannot find the valid link for pypi (url:{ new_link } ' )
233+ return ret , new_link
212234 except Exception :
213235 oss_name = re .sub (r"[-]+" , "_" , oss_name )
214236 new_link = f'{ host } /packages/source/{ oss_name [0 ]} /{ oss_name } /{ oss_name } -{ oss_version } .tar.gz'
215- res = urlopen (new_link )
216- if res .getcode () == 200 :
217- ret = True
218- else :
219- logger .warning (f'Cannot find the valid link for pypi (url:{ new_link } ' )
237+ try :
238+ res = urlopen (new_link )
239+ if res .getcode () == 200 :
240+ ret = True
241+ return ret , new_link
242+ except Exception :
243+ pass
244+
245+ # 2. Source distribution이 없으면 wheel 파일들을 시도
246+ wheel_urls = get_available_wheel_urls (oss_name , oss_version )
247+
248+ if wheel_urls :
249+ # Pure Python wheel을 우선적으로 찾기
250+ for wheel_url in wheel_urls :
251+ if 'py3-none-any' in wheel_url or 'py2.py3-none-any' in wheel_url :
252+ try :
253+ res = urlopen (wheel_url )
254+ if res .getcode () == 200 :
255+ ret = True
256+ new_link = wheel_url
257+ logger .info (f'Using wheel file : { wheel_url } ' )
258+ return ret , new_link
259+ except Exception :
260+ continue
261+
262+ # Pure Python wheel이 없으면 첫 번째 wheel 시도
263+ if wheel_urls :
264+ try :
265+ res = urlopen (wheel_urls [0 ])
266+ if res .getcode () == 200 :
267+ ret = True
268+ new_link = wheel_urls [0 ]
269+ logger .info (f'Using wheel file : { wheel_urls [0 ]} ' )
270+ return ret , new_link
271+ except Exception :
272+ pass
273+
220274 except Exception as error :
221275 ret = False
222- logger .warning (f'Cannot find the link for pypi (url:{ link } ({ ( new_link ) } )) e:{ str (error )} ' )
276+ logger .warning (f'Cannot find the link for pypi (url:{ link } ({ new_link } )) e:{ str (error )} ' )
223277
224278 return ret , new_link
225279
0 commit comments