<commit_before>import pkg_resources
import sys

from floyd.exceptions import FloydException
from floyd.manager.auth_config import AuthConfigManager
from floyd.manager.experiment_config import ExperimentConfigManager
from floyd.manager.data_config import DataConfigManager

from floyd.constants import DOCKER_IMAGES


def get_docker_image(env, gpu):
    gpu_cpu = "gpu" if gpu else "cpu"
    return DOCKER_IMAGES.get(gpu_cpu).get(env)


def get_module_task_instance_id(task_instances):
    """
    Return the first task instance that is a module node.
    """
    for id in task_instances:
        if task_instances[id] == 'module_node':
            return id
    return None


def get_mode_parameter(mode):
    """
    Map the mode parameter to the server parameter
    """
    if mode == 'job':
        return 'cli'
    elif mode == 'serve':
        return 'serving'
    else:
        return mode


def get_data_name(data_str, default=None):
    """
    If data_str is of the format <ID>:<NAME>, return <NAME>
    Else return default if default is present
    Otherwise return ID itself
    """
    if ':' in data_str:
        _, name = data_str.split(':')
    else:
        name = default if default else data_str
    return name


def get_data_id(data_str):
    """
    If data_str is of the format <ID>:<NAME>, or <URI>/<PATH>:<NAME>
    return ID or URI
    """
    if ':' in data_str:
        name_or_id, _ = data_str.split(':')
        return name_or_id
    else:
        return data_str


def normalize_data_name(raw_name, default_username='', default_dataset_name='', use_data_config=True):
    raw_name = raw_name or ''
    if use_data_config:
        default_dataset_name = default_dataset_name or current_dataset_name()

    if raw_name.endswith('/output'):
        return normalize_job_name(raw_name[:-len('/output')], default_username, default_dataset_name) + '/output'

    name_parts = raw_name.split('/')

    namespace = default_username or current_dataset_namespace()
    name = default_dataset_name
    number = None  # current version number

    # When nothing is passed, use all the defaults
    if not raw_name:
        pass
    elif len(name_parts) == 4:
        # mckay/datasets/foo/1
        namespace, _, name, number = name_parts
    elif len(name_parts) == 3:

        if name_parts[2].isdigit():
            # mckay/foo/1
            namespace, name, number = name_parts
        else:
            # mckay/projects/foo
            namespace, _, name = name_parts
    elif len(name_parts) == 2:
        if name_parts[1].isdigit():
            # foo/1
            name, number = name_parts
        else:<commit_msg>fix: honor use_data_config in data name normalization<commit_after>import pkg_resources
import sys

from floyd.exceptions import FloydException
from floyd.manager.auth_config import AuthConfigManager
from floyd.manager.experiment_config import ExperimentConfigManager
from floyd.manager.data_config import DataConfigManager

from floyd.constants import DOCKER_IMAGES


def get_docker_image(env, gpu):
    gpu_cpu = "gpu" if gpu else "cpu"
    return DOCKER_IMAGES.get(gpu_cpu).get(env)


def get_module_task_instance_id(task_instances):
    """
    Return the first task instance that is a module node.
    """
    for id in task_instances:
        if task_instances[id] == 'module_node':
            return id
    return None


def get_mode_parameter(mode):
    """
    Map the mode parameter to the server parameter
    """
    if mode == 'job':
        return 'cli'
    elif mode == 'serve':
        return 'serving'
    else:
        return mode


def get_data_name(data_str, default=None):
    """
    If data_str is of the format <ID>:<NAME>, return <NAME>
    Else return default if default is present
    Otherwise return ID itself
    """
    if ':' in data_str:
        _, name = data_str.split(':')
    else:
        name = default if default else data_str
    return name


def get_data_id(data_str):
    """
    If data_str is of the format <ID>:<NAME>, or <URI>/<PATH>:<NAME>
    return ID or URI
    """
    if ':' in data_str:
        name_or_id, _ = data_str.split(':')
        return name_or_id
    else:
        return data_str


def normalize_data_name(raw_name, default_username='', default_dataset_name='', use_data_config=True):
    raw_name = raw_name or ''
    if raw_name.endswith('/output'):
        return normalize_job_name(raw_name[:-len('/output')], default_username, default_dataset_name) + '/output'

    name_parts = raw_name.split('/')

    namespace = default_username
    if use_data_config:
        default_dataset_name = default_dataset_name or current_dataset_name()
        namespace = namespace or current_dataset_namespace()

    name = default_dataset_name
    number = None  # current version number

    # When nothing is passed, use all the defaults
    if not raw_name:
        pass
    elif len(name_parts) == 4:
        # mckay/datasets/foo/1
        namespace, _, name, number = name_parts
    elif len(name_parts) == 3:
        if name_parts[2].isdigit():
            # mckay/foo/1
            namespace, name, number = name_parts
        else:
            # mckay/projects/foo
            namespace, _, name = name_parts
    elif len(name_parts) == 2:
        if name_parts[1].isdigit():
            # foo/1
            name, number = name_parts
        else:
{'fraction_non_alphanumeric': 0.09374416433239963, 'fraction_numerical': 0.002987861811391223, 'mean_word_length': 2.7905166312809624, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5129860', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1622, 'n_words': 451}