Skip to content

Commit

Permalink
Update setup.py to download HMMs from the official location if GitH…
Browse files Browse the repository at this point in the history
…ub cannot be reached
  • Loading branch information
althonos committed Jul 23, 2020
1 parent 91f30b4 commit 54b79b6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,15 @@ def run(self):
def download(self, output, options):
base = "https://github.com/althonos/GECCO/releases/download/v{version}/{id}.hmm.gz"
url = base.format(id=options["id"], version=self.distribution.get_version())
self.announce("fetching {}".format(url), level=2)
with ResponseProgressBar(urllib.request.urlopen(url), desc=os.path.basename(output)) as src:
# attempt to use the GitHub releases URL, otherwise fallback to official URL
try:
self.announce("fetching {}".format(url), level=2)
response = urllib.request.urlopen(url)
except urllib.error.HTTPError:
self.announce("using fallback {}".format(options["url"]), level=2)
response = urllib.request.urlopen(options["url"])
# download the HMM
with ResponseProgressBar(response, desc=os.path.basename(output)) as src:
with open(output, "wb") as dst:
shutil.copyfileobj(src, dst)

Expand Down

0 comments on commit 54b79b6

Please sign in to comment.