<commit_before>import os
import sys
import inspect
import importlib
from contextlib import contextmanager


def get_fully_qualified_function_name(f):
    """For a given function return it's fully qualified name as str."""
    module_name = f.__module__
    if module_name == '__main__':
        module_name = get_main_module()[1]

    if inspect.ismethod(f):
        return module_name + '.' + f.__self__.__name__ + '.' + f.__name__
    else:
        return module_name + '.' + f.__name__


def import_task(fully_qualified_function_name):
    """Find and return the function for given function name."""
    module_name, func_name = fully_qualified_function_name.rsplit('.', 1)
    module = import_task_module(module_name)
    return getattr(module, func_name)


def import_task_module(module_name):
    """Import module by searching main module, current working directory and
    python path."""
    main_module, main_module_name = get_main_module()
    if module_name == main_module_name:
        return main_module
    else:
        return import_from_cwd(module_name)


def import_from_cwd(module):
    """Import the module from current working directory."""
    with cwd_in_path():
        return importlib.import_module(module)


@contextmanager
def cwd_in_path():
    cwd = os.getcwd()
    if cwd in sys.path:<commit_msg>only module level functions can be tasks<commit_after>import os
import sys
import logging
import importlib
from contextlib import contextmanager

logger = logging.getLogger(__name__)


def get_fully_qualified_function_name(f):
    """For a given function return it's fully qualified name as str."""
    module_name = f.__module__
    if module_name == '__main__':
        module_name = get_main_module()[1]

    return module_name + '.' + f.__name__


def import_task(fully_qualified_function_name):
    """Find and return the function for given function name."""
    logger.debug('fq name: %s', fully_qualified_function_name)
    module_name, func_name = fully_qualified_function_name.rsplit('.', 1)
    module = import_task_module(module_name)
    return getattr(module, func_name)


def import_task_module(module_name):
    """Import module by searching main module, current working directory and
    python path."""
    main_module, main_module_name = get_main_module()
    if module_name == main_module_name:
        return main_module
    else:
        return import_from_cwd(module_name)


def import_from_cwd(module):
    """Import the module from current working directory."""
    with cwd_in_path():
        return importlib.import_module(module)


@contextmanager
def cwd_in_path():
    cwd = os.getcwd()
    if cwd in sys.path:
{'fraction_non_alphanumeric': 0.08927231807951988, 'fraction_numerical': 0.0015003750937734434, 'mean_word_length': 4.032075471698113, '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': '1825408', 'n_tokens_mistral': 807, 'n_tokens_neox': 783, 'n_words': 222}