<commit_before>'''
The Python module allows you to execute Python code within the context of a deploy.
'''

from pyinfra.api import FunctionCommand, operation


@operation
def call(state, host, function, args=None, kwargs=None):
    '''
    Execute a Python function within a deploy.

    + func: the function to execute
    + args: additional arguments to pass to the function
    + kwargs: additional keyword arguments to pass to the function

    Callback functions args passed the state, host, and any args/kwargs passed
    into the operation directly, eg:

    .. code:: python

        def my_callback(state, host, hello=None):
            command = 'echo hello'
            if hello:
                command = command + ' ' + hello
            status, stdout, stderr = host.run_shell_command(state, command=command, sudo=SUDO)
            assert status is True  # ensure the command executed OK
            if 'hello ' not in str(stdout):
                raise Exception('`{}` problem with callback stdout:{} stderr:{}'.format(
                    command, stdout, stderr))
<commit_msg>Restore reading `*args` and `*kwargs` in `python.call` operation.<commit_after>'''
The Python module allows you to execute Python code within the context of a deploy.
'''

from pyinfra.api import FunctionCommand, operation


@operation
def call(state, host, function, *args, **kwargs):
    '''
    Execute a Python function within a deploy.

    + func: the function to execute
    + args: additional arguments to pass to the function
    + kwargs: additional keyword arguments to pass to the function

    Callback functions args passed the state, host, and any args/kwargs passed
    into the operation directly, eg:

    .. code:: python

        def my_callback(state, host, hello=None):
            command = 'echo hello'
            if hello:
                command = command + ' ' + hello
            status, stdout, stderr = host.run_shell_command(state, command=command, sudo=SUDO)
            assert status is True  # ensure the command executed OK
            if 'hello ' not in str(stdout):
                raise Exception('`{}` problem with callback stdout:{} stderr:{}'.format(
                    command, stdout, stderr))

{'fraction_non_alphanumeric': 0.0864308105687416, 'fraction_numerical': 0.0, 'mean_word_length': 2.6622950819672133, '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': '1181049', 'n_tokens_mistral': 581, 'n_tokens_neox': 551, 'n_words': 241}