<commit_before>"""
Handle loading six package from system or from the bundled copy
"""

import imp


_SIX_SEARCH_PATH = ['setuptools._vendor.six', 'six']


def _find_module(name, path=None):
    """
    Alternative to `imp.find_module` that can also search in subpackages.
    """

    parts = name.split('.')

    for part in parts:
        if path is not None:
            path = [path]

        fh, path, descr = imp.find_module(part, path)

    return fh, path, descr


def _import_six(search_path=_SIX_SEARCH_PATH):
    for mod_name in search_path:
        try:
            mod_info = _find_module(mod_name)
        except ImportError:
            continue

        imp.load_module(__name__, *mod_info)

        break

    else:
        raise ImportError(
            "The 'six' module of minimum version {0} is required; "
            "normally this is bundled with this package so if you get "
            "this warning, consult the packager of your "
            "distribution.")


_import_six()<commit_msg>Make the technique even more generic<commit_after>"""
Handle loading a package from system or from the bundled copy
"""

import imp


_SEARCH_PATH = ['setuptools._vendor.six', 'six']


def _find_module(name, path=None):
    """
    Alternative to `imp.find_module` that can also search in subpackages.
    """

    parts = name.split('.')

    for part in parts:
        if path is not None:
            path = [path]

        fh, path, descr = imp.find_module(part, path)

    return fh, path, descr


def _import_in_place(search_path=_SEARCH_PATH):
    for mod_name in search_path:
        try:
            mod_info = _find_module(mod_name)
        except ImportError:
            continue

        imp.load_module(__name__, *mod_info)
        break

    else:
        raise ImportError(
            "The '{name}' package is required; "
            "normally this is bundled with this package so if you get "
            "this warning, consult the packager of your "
            "distribution.".format(name=_SEARCH_PATH[-1]))


_import_in_place()
{'fraction_non_alphanumeric': 0.09064469219583131, 'fraction_numerical': 0.0009694619486185168, 'mean_word_length': 2.367047308319739, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3481735', 'n_tokens_mistral': 631, 'n_tokens_neox': 606, 'n_words': 196}