Skip to content

Commit 522546c

Browse files
committed
Merge branch 'release_24.2' into release_25.0
2 parents 16e8252 + 7e8182b commit 522546c

2 files changed

Lines changed: 50 additions & 41 deletions

File tree

lib/galaxy/tool_util/deps/mulled/get_tests.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
118111
def 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

151150
def 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}

test/unit/tool_util/mulled/test_get_tests.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from galaxy.tool_util.deps.mulled.get_tests import (
44
deep_test_search,
5-
find_anaconda_versions,
5+
find_anaconda_download_url,
66
get_alternative_versions,
77
get_anaconda_url,
88
get_commands_from_yaml,
@@ -11,7 +11,6 @@
1111
hashed_test_search,
1212
main_test_search,
1313
open_recipe_file,
14-
prepend_anaconda_url,
1514
)
1615
from galaxy.util import smart_str
1716
from ..util import external_dependency_management
@@ -49,11 +48,6 @@ def test_get_anaconda_url():
4948
assert url == "https://anaconda.org/bioconda/samtools/1.7/download/linux-64/samtools-1.7-1.tar.bz2"
5049

5150

52-
def test_prepend_anaconda_url():
53-
url = prepend_anaconda_url("/bioconda/samtools/0.1.12/download/linux-64/samtools-0.1.12-2.tar.bz2")
54-
assert url == "https://anaconda.org/bioconda/samtools/0.1.12/download/linux-64/samtools-0.1.12-2.tar.bz2"
55-
56-
5751
@external_dependency_management
5852
def test_get_test_from_anaconda():
5953
# test old fashion tar.bz2 package
@@ -81,9 +75,20 @@ def test_get_test_from_anaconda():
8175

8276

8377
@external_dependency_management
84-
def test_find_anaconda_versions():
85-
versions = find_anaconda_versions("2pg_cartesian")
86-
assert "/bioconda/2pg_cartesian/1.0.1/download/linux-64/2pg_cartesian-1.0.1-0.tar.bz2" in versions
78+
def test_find_anaconda_download_url():
79+
download_url = find_anaconda_download_url("2pg_cartesian", "1.0.0")
80+
assert download_url is None
81+
download_url = find_anaconda_download_url("2pg_cartesian", "1.0.1")
82+
assert download_url is not None
83+
assert download_url.startswith(
84+
"https://api.anaconda.org/download/bioconda/2pg_cartesian/1.0.1/linux-64/2pg_cartesian-1.0.1-"
85+
)
86+
download_url = find_anaconda_download_url("2pg_cartesian", "1.0.1", "0")
87+
assert download_url is not None
88+
assert (
89+
download_url
90+
== "https://api.anaconda.org/download/bioconda/2pg_cartesian/1.0.1/linux-64/2pg_cartesian-1.0.1-0.tar.bz2"
91+
)
8792

8893

8994
@external_dependency_management

0 commit comments

Comments
 (0)