<commit_before>__all__ = ['bootstrap']


# Monkey patch fabric
from .patch import patch
patch('fabric.operations.run')
patch('fabric.operations.sudo', 'refabric.operations.run')
patch('fabric.state.switch_env')
patch('fabric.tasks._execute')
patch('fabric.tasks.Task:get_hosts_and_effective_roles')
patch('fabric.utils._AttributeDict')


# Reload fabric's run/sudo internal import references to patched version
import fabric.api
import fabric.contrib.files
import fabric.contrib.project
import fabric.operations
for m in (fabric.api, fabric.contrib.files, fabric.contrib.project):
    m.run = m.sudo = fabric.operations.run


def bootstrap():
    """
    Define global blueprint tasks, load configured blueprints and apply role definitions.
    """
    import fabric.state
    from fabric.decorators import task

    from .state import load_blueprints
    from .tasks import help_task, init_task

    # Set environment defaults
    fabric.state.env.update({
        'sudo_user': 'root',
        'colorize_errors': True,
        'skip_unknown_tasks': True,
        'merge_states': True,
        'prompt_hosts': True,
        'forward_agent': True,
        'sudo_prefix': "sudo -S -E -p '%(sudo_prompt)s' SSH_AUTH_SOCK=$SSH_AUTH_SOCK",
    })

    # Create global blueprint tasks
    fabric.state.commands['help'] = task(help_task)
    fabric.state.commands['init'] = task(init_task)

    # Load configured blueprints
    load_blueprints()

    # Touch env.roles to trigger apply role definitions (needed for cli options -R, --list etc.)
    fabric.state.env.roles = fabric.state.env.roles
<commit_msg>Move fabric patching to bootstrap<commit_after>__all__ = ['bootstrap']


def bootstrap():
    """
    Define global blueprint tasks, load configured blueprints and apply role definitions.
    """
    # Monkey patch fabric
    from .patch import patch
    patch('fabric.operations.run')
    patch('fabric.operations.sudo', 'refabric.operations.run')
    patch('fabric.state.switch_env')
    patch('fabric.tasks._execute')
    patch('fabric.tasks.Task:get_hosts_and_effective_roles')
    patch('fabric.utils._AttributeDict')

    # Reload fabric's run/sudo internal import references to patched version
    import fabric.api
    import fabric.contrib.files
    import fabric.contrib.project
    import fabric.operations
    for m in (fabric.api, fabric.contrib.files, fabric.contrib.project):
        m.run = m.sudo = fabric.operations.run

    import fabric.state
    from fabric.decorators import task

    from .state import load_blueprints
    from .tasks import help_task, init_task

    # Set environment defaults
    fabric.state.env.update({
        'sudo_user': 'root',
        'colorize_errors': True,
        'skip_unknown_tasks': True,
        'merge_states': True,
        'prompt_hosts': True,
        'forward_agent': True,
        'sudo_prefix': "sudo -S -E -p '%(sudo_prompt)s' SSH_AUTH_SOCK=$SSH_AUTH_SOCK",
    })

    # Create global blueprint tasks
    fabric.state.commands['help'] = task(help_task)
    fabric.state.commands['init'] = task(init_task)

    # Load configured blueprints
    load_blueprints()

    # Touch env.roles to trigger apply role definitions (needed for cli options -R, --list etc.)
    fabric.state.env.roles = fabric.state.env.roles

{'fraction_non_alphanumeric': 0.11043319097010372, 'fraction_numerical': 0.0, 'mean_word_length': 3.5103163686382395, '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': '7182143', 'n_tokens_mistral': 1009, 'n_tokens_neox': 943, 'n_words': 246}