from pathlib import Path


def find_downloads(folder):
    """Find artifact links in _downloads file.

    The _downloads file should be created by the doctr_build.sh script.
    If no _downloads file exists, return an empty list.
    """
    downloads = []
    try:
        with open(Path(folder) / "_downloads") as in_fh:
            for url in in_fh:
                url = url.strip()
                label = url.split(".")[-1].lower()
                print("For %s, download link %r => %r" % (folder, label, url))
                downloads.append((label, url))
    except IOError:
        print("WARNING: $%s contains no _downloads" % folder)
    return downloads