diff --git a/build_defs/python.build_defs b/build_defs/python.build_defs index 07261274..aa4f979d 100644 --- a/build_defs/python.build_defs +++ b/build_defs/python.build_defs @@ -548,23 +548,17 @@ def python_wheel(name:str, version:str, hashes:list=None, package_name:str=None, file_rule = None if tool: - # Try the urls generated using the default wheel name schemes. If those fail, try + # Try the URLs generated using the wheel name schemes. If those fail, try # generating a url with the wheel_resolver tool and download that if successful. - cmd = ['FOUND=false; DOWNLOAD=""'] - cmd += ['for URL in ' + ' '.join(urls)] - cmd += ['do if wget -q --method=HEAD $URL'] - cmd += ['then FOUND=true; DOWNLOAD="$URL"'] - cmd += ['break; fi; done'] - - cmd += ['if [ "$FOUND" = true ]'] - cmd += ['then wget -O "$OUTS" "$DOWNLOAD"'] - cmd += ['else $TOOL --package ' + package_name + ' --version ' + version + '; fi'] + cmd = f'$TOOL --package {package_name} --version {version}' + if urls: + cmd += ' --urls ' + ' '.join(['%s' % url for url in urls]) file_rule = build_rule( name = name, tag = 'download', outs = [name + '.whl'], - cmd = '; '.join(cmd), + cmd = cmd, tools = [tool], hashes = hashes if CONFIG.FF_PYTHON_WHEEL_HASHING else None, licences = licences if licences else None, diff --git a/tools/wheel_resolver/resolve.py b/tools/wheel_resolver/resolve.py index b72084b8..157b3ece 100644 --- a/tools/wheel_resolver/resolve.py +++ b/tools/wheel_resolver/resolve.py @@ -10,13 +10,22 @@ import sys -def download(url): +def try_download(url): + """ + Try to download url to $OUTS. Returns false if + it failed. + """ output = os.environ.get("OUTS") if output is None: logging.critical("No output directory found") sys.exit(1) - urllib.request.urlretrieve(url, output) + try: + urllib.request.urlretrieve(url, output) + except urllib.error.HTTPError: + return False + + return True def main(): @@ -42,9 +51,21 @@ def main(): type=str, default=[], help='specify architecture') + parser.add_argument( + '--urls', + nargs="*", + type=str, + default=[], + help='URLs to try before looking in wheel index') args = parser.parse_args() + # If any URLs were passed, try them first before looking in the wheel index + if args.urls: + for url in args.urls: + if try_download(url): + return + # Fetch all available wheel urls from index urls = tg.get_download_urls(args.package, args.version) if urls is None: @@ -54,10 +75,11 @@ def main(): result = tg.get_url(urls, args.arch) if result is not None: - download(result) - else: - logging.critical("Found %s urls but none are compatible", len(urls)) - sys.exit(1) + if try_download(result): + return + + logging.critical("Found %s URLs but none are compatible", len(urls)) + sys.exit(1) main()