How to use pooch - 10 common examples

To help you get started, we’ve selected a few pooch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fatiando / pooch / pooch / _version.py View on Github external
if not keywords:
        raise NotThisMethod("no keywords at all, weird")
    date = keywords.get("date")
    if date is not None:
        # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
        # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
        # -like" string, which we must then edit to make compliant), because
        # it's been around since git-1.5.3, and it's too difficult to
        # discover which version we're using, or to work around using an
        # older one.
        date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
    refnames = keywords["refnames"].strip()
    if refnames.startswith("$Format"):
        if verbose:
            print("keywords are unexpanded, not using")
        raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
    refs = set([r.strip() for r in refnames.strip("()").split(",")])
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
    # just "foo-1.0". If we see a "tag: " prefix, prefer those.
    TAG = "tag: "
    tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)])
    if not tags:
        # Either we're using git < 1.8.3, or there really are no tags. We use
        # a heuristic: assume all version tags have a digit. The old git %d
        # expansion behaves like git log --decorate=short and strips out the
        # refs/heads/ and refs/tags/ prefixes that would let us distinguish
        # between branches and tags. By ignoring refnames without digits, we
        # filter out many common branch names like "release" and
        # "stabilization", as well as "HEAD" and "master".
        tags = set([r for r in refs if re.search(r"\d", r)])
        if verbose:
            print("discarding '%s', no digits" % ",".join(refs - tags))
github fatiando / pooch / pooch / _version.py View on Github external
def git_versions_from_keywords(keywords, tag_prefix, verbose):
    """Get version information from git keywords."""
    if not keywords:
        raise NotThisMethod("no keywords at all, weird")
    date = keywords.get("date")
    if date is not None:
        # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
        # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
        # -like" string, which we must then edit to make compliant), because
        # it's been around since git-1.5.3, and it's too difficult to
        # discover which version we're using, or to work around using an
        # older one.
        date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
    refnames = keywords["refnames"].strip()
    if refnames.startswith("$Format"):
        if verbose:
            print("keywords are unexpanded, not using")
        raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
    refs = set([r.strip() for r in refnames.strip("()").split(",")])
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
github fatiando / pooch / pooch / core.py View on Github external
Parameters
        ----------
        fname : str
            The file name (relative to the *base_url* of the remote data
            storage) to fetch from the local storage.

        Returns
        -------
        status : bool
            True if the file is available for download. False otherwise.

        """
        self._assert_file_in_registry(fname)
        source = self.get_url(fname)
        parsed_url = parse_url(source)
        if parsed_url["protocol"] == "ftp":
            directory, file_name = os.path.split(parsed_url["path"])
            ftp = ftplib.FTP()
            ftp.connect(host=parsed_url["netloc"])
            try:
                ftp.login()
                available = file_name in ftp.nlst(directory)
            finally:
                ftp.close()
        else:
            response = requests.head(source, allow_redirects=True)
            available = bool(response.status_code == 200)
        return available
github fatiando / pooch / pooch / __init__.py View on Github external
# pylint: disable=missing-docstring,import-outside-toplevel
# Import functions/classes to make the API
from . import version
from .core import Pooch, create, retrieve
from .utils import os_cache, file_hash, make_registry, check_version, get_logger
from .downloaders import HTTPDownloader, FTPDownloader, SFTPDownloader
from .processors import Unzip, Untar, Decompress


__version__ = version.full_version


def test(doctest=True, verbose=True, coverage=False):
    """
    Run the test suite.

    Uses `py.test `__ to discover and run the tests.

    Parameters
    ----------

    doctest : bool
        If ``True``, will run the doctests as well (code examples that start
        with a ``>>>`` in the docs).
    verbose : bool
        If ``True``, will print extra information during the test run.
github fatiando / pooch / doc / conf.py View on Github external
plot_include_source = True
plot_formats = ["png"]

# Sphinx project configuration
templates_path = ["_templates"]
exclude_patterns = ["_build", "**.ipynb_checkpoints"]
source_suffix = ".rst"
# The encoding of source files.
source_encoding = "utf-8-sig"
master_doc = "index"

# General information about the project
year = datetime.date.today().year
project = "Pooch"
copyright = "2018-{}, The Pooch Developers".format(year)
if len(full_version.split("+")) > 1 or full_version == "unknown":
    version = "dev"
else:
    version = full_version

# These enable substitutions using |variable| in the rst files
rst_epilog = """
.. |year| replace:: {year}
""".format(
    year=year
)

html_last_updated_fmt = "%b %d, %Y"
html_title = project
html_short_title = project
html_logo = "_static/pooch-logo.png"
html_favicon = "_static/favicon.png"
github JustinGOSSES / predictatops / predictatops / fetch_demo_data.py View on Github external
NOTE: This was changed since version 1 to pull in a single zip file and unzip it as that's faster than pulling in each file unzipped individually!
"""


##### import statements #####
import pooch
import os
from zipfile import ZipFile

# Get the version string from your project. You have one of these, right?
# from . import version

data_path = "../data/Mannville_input_data/"

# Create a new friend to manage your sample data storage
GOODBOY = pooch.create(
    # Folder where the data will be stored. For a sensible default, use the default
    # cache folder for your OS.
    # path=pooch.os_cache("mypackage_test"),
    # path=pooch.os_cache("mypackage_test"),
    path=data_path,
    # Base URL of the remote data store. Will call .format on this string to insert
    # https://github.com/JustinGOSSES/predictatops/
    # the version (see below).  https://github.com/JustinGOSSES/MannvilleGroup_Strat_Hackathon/tree/master/SPE_006_originalData
    #base_url="https://github.com/JustinGOSSES/predictatops/raw/{version}/demo/mannville_demo_data/",
    base_url="https://github.com/JustinGOSSES/predictatops/raw/{version}/demo/",
    # Pooches are versioned so that you can use multiple versions of a package
    # simultaneously. Use PEP440 compliant version number. The version will be
    # appended to the path.
    #version="v0.0.0-alpha",
    version="v0.0.3-alpha",
    # If a version as a "+XX.XXXXX" suffix, we'll assume that this is a dev version
github icepack / icepack / icepack / datasets.py View on Github external
password = getpass('EarthData password: ')
    auth = (username, password)

    login = requests.get(url)
    downloader = pooch.HTTPDownloader(auth=auth, progressbar=True)
    try:
        downloader(login.url, output_file, dataset)
    except requests.exceptions.HTTPError as error:
        if 'Unauthorized' in str(error):
            pooch.get_logger().error('Wrong username/password!')
        raise error


nsidc_url = 'https://daacdata.apps.nsidc.org/pub/DATASETS/'

measures_antarctica = pooch.create(
    path=pooch.os_cache('icepack'),
    base_url='https://n5eil01u.ecs.nsidc.org/MEASURES/NSIDC-0754.001/1996.01.01/',
    registry={
        'antarctic_ice_vel_phase_map_v01.nc':
        'fa0957618b8bd98099f4a419d7dc0e3a2c562d89e9791b4d0ed55e6017f52416'
    }
)

def fetch_measures_antarctica():
    return measures_antarctica.fetch('antarctic_ice_vel_phase_map_v01.nc',
                                     downloader=_earthdata_downloader)


measures_greenland = pooch.create(
    path=pooch.os_cache('icepack'),
    base_url=nsidc_url + 'NSIDC-0478.002/2015.0.01/',
github icepack / icepack / icepack / datasets.py View on Github external
path=pooch.os_cache('icepack'),
    base_url='https://n5eil01u.ecs.nsidc.org/MEASURES/NSIDC-0756.001/1970.01.01/',
    registry={
        'BedMachineAntarctica_2019-11-05_v01.nc':
        '06a01511a51bbc27d5080e4727a6523126659fe62402b03654a5335e25b614c0'
    }
)

def fetch_bedmachine_antarctica():
    return bedmachine_antarctica.fetch('BedMachineAntarctica_2019-11-05_v01.nc',
                                       downloader=_earthdata_downloader)


outlines_url = 'https://raw.githubusercontent.com/icepack/glacier-meshes/'
outlines_commit = 'a522188dadb9ba49d4848ba66cab8c90f9fda5d9'
larsen_outline = pooch.create(
    path=pooch.os_cache('icepack'),
    base_url=outlines_url + outlines_commit + '/glaciers/',
    registry={
        'larsen.geojson':
        'da77c1920191d415961347b43e18d5bc2ffd72ddb803c01fc24c68c5db0f3033'
    }
)

def fetch_larsen_outline():
    return larsen_outline.fetch(
        'larsen.geojson', downloader=pooch.HTTPDownloader(progressbar=True)
    )


moa = pooch.create(
    path=pooch.os_cache('icepack'),
github fatiando / rockhound / rockhound / registry.py View on Github external
"""
Create a dataset registry using Pooch and the rockhound/registry.txt file.
"""
import os

import pooch


REGISTRY = pooch.create(
    path=pooch.os_cache("rockhound"), base_url="", env="ROCKHOUND_DATA_DIR"
)
REGISTRY.load_registry(os.path.join(os.path.dirname(__file__), "registry.txt"))


def data_location():
    r"""
    The absolute path to the data storage location on disk.

    This is where the data sets are saved on your computer. The data location
    is dependent on the operating system. The folder locations are defined by
    the ``appdirs``  package (see the
    `appdirs documentation `__).
    It can also be overwritten by the ``ROCKHOUND_DATA_DIR`` environment
    variable.
github mathause / regionmask / regionmask / defined_regions / _ressources.py View on Github external
import geopandas as gp
import pooch

REMOTE_RESSOURCE = pooch.create(
    # Use the default cache folder for the OS
    path=pooch.os_cache("regionmask"),
    # The remote data is on Github
    base_url="https://github.com/mathause/regionmask/raw/master/data/",
    registry={
        "CMIP6_referenceRegions.zip": "d05cd29fb0d0f21e696f118efdb9e9d87815096844d52d989affd513e9f597d1",
        "CMIP6_referenceRegions_pre_revisions.zip": "8507cef52057785117cabc83d6e03414b5994745bf7f297c179eb50507f7ee89",
    },
)


def fetch_remote_shapefile(name):
    """
    uses pooch to cache files
    """