<commit_before># Copyright (c) 2008,2015,2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Collection of generally useful utility code from the cookbook."""

import os
from pathlib import Path

import numpy as np
import pooch

from . import __version__

pooch_kwargs = {'path': pooch.os_cache('metpy')}

# Check if we have the data available directly from a git checkout, either from the
# TEST_DATA_DIR variable, or looking relative to the path of this module's file. Use this
# to override Pooch's path and disable downloading from GitHub.
dev_data_path = os.environ.get('TEST_DATA_DIR', Path(__file__).parents[2] / 'staticdata')
if Path(dev_data_path).exists():
    pooch_kwargs['path'] = dev_data_path
    if pooch.__version__ >= 'v1.6.0':
        pooch_kwargs['allow_updates'] = False

POOCH = pooch.create(
    base_url='https://github.com/Unidata/MetPy/raw/{version}/staticdata/',
    version='v' + __version__,
    version_dev='main',
    **pooch_kwargs)

POOCH.load_registry(Path(__file__).parent / 'static-data-manifest.txt')


def get_test_data(fname, as_file_obj=True, mode='rb'):
    """Access a file from MetPy's collection of test data."""
    path = POOCH.fetch(fname)
    # If we want a file object, open it, trying to guess whether this should be binary mode
    # or not
    if as_file_obj:
        return open(path, mode)  # noqa: SIM115

    return path
<commit_msg>TEST: Fix unneeded downloading of test data on git checkouts<commit_after># Copyright (c) 2008,2015,2018,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Collection of generally useful utility code from the cookbook."""

import os
from pathlib import Path

import numpy as np
import pooch

from . import __version__

pooch_kwargs = {'path': pooch.os_cache('metpy'), 'version': 'v' + __version__,
                'base_url': 'https://github.com/Unidata/MetPy/raw/{version}/staticdata/'}

# Check if we have the data available directly from a git checkout, either from the
# TEST_DATA_DIR variable, or looking relative to the path of this module's file. Use this
# to override Pooch's path and disable downloading from GitHub.
dev_data_path = os.environ.get('TEST_DATA_DIR', Path(__file__).parents[2] / 'staticdata')
if Path(dev_data_path).exists():
    pooch_kwargs['path'] = dev_data_path
    pooch_kwargs['version'] = None
    pooch_kwargs['base_url'] = pooch_kwargs['base_url'].format(version='main')
    if pooch.__version__ >= 'v1.6.0':
        pooch_kwargs['allow_updates'] = False

POOCH = pooch.create(version_dev='main', **pooch_kwargs)
POOCH.load_registry(Path(__file__).parent / 'static-data-manifest.txt')


def get_test_data(fname, as_file_obj=True, mode='rb'):
    """Access a file from MetPy's collection of test data."""
    path = POOCH.fetch(fname)
    # If we want a file object, open it, trying to guess whether this should be binary mode
    # or not
    if as_file_obj:
        return open(path, mode)  # noqa: SIM115

    return path

{'fraction_non_alphanumeric': 0.11197160374314295, 'fraction_numerical': 0.016134236850596968, 'mean_word_length': 4.317324185248713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6568534', 'n_tokens_mistral': 1028, 'n_tokens_neox': 986, 'n_words': 308}