From 54b79b6142badb7d2180277fd7b1fe799fa943f7 Mon Sep 17 00:00:00 2001 From: Martin Larralde Date: Thu, 23 Jul 2020 16:23:49 +0200 Subject: [PATCH] Update `setup.py` to download HMMs from the official location if GitHub cannot be reached --- setup.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 62578ca..680cc6a 100644 --- a/setup.py +++ b/setup.py @@ -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)