Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds alternate lookup if base lookup fails #896

Merged
merged 4 commits into from
Jul 6, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions bioconda_utils/hosters.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,61 @@ class GithubBase(OrderedHTMLHoster):
class GithubRelease(GithubBase):
"""Matches release artifacts uploaded to Github"""
link_pattern = r"/{account}/{project}/releases/download/{tag}/{fname}{ext}?"
alt_releases_formats = ["https://api.github.com/repos/{account}/{project}/releases"]

async def get_versions(self, req, orig_version):
# first, try the older version when HTML worked
matches = await super().get_versions(req, orig_version)
if len(matches) > 0:
return matches

# old version found nothing, try with the alternate github API URLs which return JSON
self.releases_urls = [
template.format_map(self.vals)
for template in self.alt_releases_formats
]

# this is basically copied from a mixture of the base version and the JSON version
# need to compile the link regex
exclude = set(self.exclude)
vals = {key: val
for key, val in self.vals.items()
if key not in exclude}
link_pattern = replace_named_capture_group(self.link_pattern_compiled, vals)
link_re = re.compile(link_pattern)

# now iterate over the alter release URLs
matches = []
for url in self.releases_urls:
text = await req.get_text_from_url(url)
data = json.loads(text)

# structured as an array of tagged releases
for tag_dict in data:
# each release has an asset dict
for asset_dict in tag_dict.get('assets', []):
# there is a direct download link for each asset, which should make the typical pattern for an HTML user
download_url = asset_dict['browser_download_url']
re_match = link_re.search(download_url)

if re_match:
# this one matches the pattern
# link - just copy the download_url in full
# version - pull out of the regex match
data = re_match.groupdict()
matches.append({
'link' : download_url,
'version' : data['version']
})

# now strip down to the version(s) that are more recent than what currently is in bioconda
num = None
for num, match in enumerate(matches):
if match["version"] == self.vals["version"]:
break
if num is None:
return matches
return matches[:num + 1]

class GithubTag(GithubBase):
"""Matches GitHub repository archives created automatically from tags"""
Expand Down