@@ -108,13 +108,6 @@ def get_anaconda_url(container, anaconda_channel="bioconda"):
108108 return f"https://anaconda.org/{ anaconda_channel } /{ name [0 ]} /{ name [1 ]} /download/linux-64/{ '-' .join (name )} .tar.bz2"
109109
110110
111- def prepend_anaconda_url (url ):
112- """
113- Take a partial url and prepend 'https://anaconda.org'
114- """
115- return f"https://anaconda.org{ url } "
116-
117-
118111def get_test_from_anaconda (url : str ) -> Optional [Dict [str , Any ]]:
119112 """
120113 Given the URL of an anaconda tarball, return tests
@@ -132,20 +125,26 @@ def get_test_from_anaconda(url: str) -> Optional[Dict[str, Any]]:
132125 return None
133126
134127
135- def find_anaconda_versions (name , anaconda_channel = "bioconda" ):
128+ def find_anaconda_download_url (
129+ name : str , version : str , build : Optional [str ] = None , anaconda_channel : str = "bioconda"
130+ ) -> Optional [str ]:
136131 """
137- Find a list of available anaconda versions for a given container name
132+ Find the anaconda download url for a given package.
138133 """
139134 r = requests .get (
140- f"https://anaconda.org/{ anaconda_channel } /{ name } /files" ,
135+ f"https://api. anaconda.org/package /{ anaconda_channel } /{ name } /files" ,
141136 timeout = MULLED_SOCKET_TIMEOUT ,
142137 )
143138 r .raise_for_status ()
144- urls = []
145- for line in r .text .splitlines ():
146- if "download/linux" in line :
147- urls .append (line .split ('"' )[1 ])
148- return urls
139+ package_files = r .json ()
140+ for package_file in reversed (package_files ):
141+ if (
142+ package_file ["version" ] == version
143+ and (build is None or package_file ["attrs" ]["build" ] == build )
144+ and package_file ["attrs" ]["subdir" ] in ["linux-64" , "noarch" ]
145+ ):
146+ return f"https:{ package_file ['download_url' ]} "
147+ return None
149148
150149
151150def open_recipe_file (file , recipes_path = None , github_repo = "bioconda/bioconda-recipes" ):
@@ -211,50 +210,55 @@ def deep_test_search(
211210 """
212211 Look in bioconda-recipes repo as well as anaconda for the tests, checking in multiple possible locations. If no test is found for the specified version, search if other package versions have a test available.
213212 """
214- name = split_container_name (container )
213+ name_tuple = split_container_name (container )
214+ assert len (name_tuple ) in (2 , 3 )
215+ name = name_tuple [0 ]
216+ version = name_tuple [1 ]
217+ build = name_tuple [2 ] if len (name_tuple ) == 3 else None
215218 for f in [
216219 (
217220 get_commands_from_yaml ,
218221 open_recipe_file ,
219- (f"recipes/{ name [ 0 ] } /{ name [ 1 ] } /meta.yaml" , recipes_path , github_repo ),
222+ (f"recipes/{ name } /{ version } /meta.yaml" , recipes_path , github_repo ),
220223 container ,
221224 ),
222225 (
223226 get_run_test ,
224227 open_recipe_file ,
225- (f"recipes/{ name [ 0 ] } /{ name [ 1 ] } /run_test.sh" , recipes_path , github_repo ),
228+ (f"recipes/{ name } /{ version } /run_test.sh" , recipes_path , github_repo ),
226229 container ,
227230 ),
228231 (
229232 get_commands_from_yaml ,
230233 open_recipe_file ,
231- (f"recipes/{ name [ 0 ] } /meta.yaml" , recipes_path , github_repo ),
234+ (f"recipes/{ name } /meta.yaml" , recipes_path , github_repo ),
232235 container ,
233236 ),
234- (get_run_test , open_recipe_file , (f"recipes/{ name [ 0 ] } /run_test.sh" , recipes_path , github_repo ), container ),
237+ (get_run_test , open_recipe_file , (f"recipes/{ name } /run_test.sh" , recipes_path , github_repo ), container ),
235238 (get_test_from_anaconda , get_anaconda_url , (container , anaconda_channel ), container ),
236239 ]:
237240 result = try_a_func (* f )
238241 if result :
239242 return result
240243
241- versions = get_alternative_versions (f"recipes/{ name [0 ]} " , "meta.yaml" , recipes_path , github_repo )
242- for version in versions :
243- result = try_a_func (get_commands_from_yaml , open_recipe_file , (version , recipes_path , github_repo ), container )
244+ alt_versions = get_alternative_versions (f"recipes/{ name } " , "meta.yaml" , recipes_path , github_repo )
245+ for alt_version in alt_versions :
246+ result = try_a_func (
247+ get_commands_from_yaml , open_recipe_file , (alt_version , recipes_path , github_repo ), container
248+ )
244249 if result :
245250 return result
246251
247- versions = get_alternative_versions (f"recipes/{ name [ 0 ] } " , "run_test.sh" , recipes_path , github_repo )
248- for version in versions :
249- result = try_a_func (get_run_test , open_recipe_file , (version , recipes_path , github_repo ), container )
252+ alt_versions = get_alternative_versions (f"recipes/{ name } " , "run_test.sh" , recipes_path , github_repo )
253+ for alt_version in alt_versions :
254+ result = try_a_func (get_run_test , open_recipe_file , (alt_version , recipes_path , github_repo ), container )
250255 if result :
251256 return result
252257
253- versions = find_anaconda_versions (name [0 ], anaconda_channel )
254- for version in versions :
255- result = try_a_func (get_test_from_anaconda , prepend_anaconda_url , (version ,), container )
256- if result :
257- return result
258+ url = find_anaconda_download_url (name , version , build = build , anaconda_channel = anaconda_channel )
259+ result = try_a_func (get_test_from_anaconda , lambda x : x , (url ,), container )
260+ if result :
261+ return result
258262
259263 # if everything fails
260264 return {"container" : container }
0 commit comments