<commit_before># -*- coding: utf-8 -*-
'''
This runner makes Salt's
execution modules available
on the salt master.

.. versionadded:: 2016.11.0

.. _salt_salt_runner:

Salt's execution modules are normally available
on the salt minion. Use this runner to call
execution modules on the salt master.
Salt :ref:`execution modules <writing-execution-modules>`
are the functions called by the ``salt`` command.

Execution modules can be called with ``salt-run``:

.. code-block:: bash

    salt-run salt.cmd test.ping
    # call functions with arguments and keyword arguments
    salt-run salt.cmd test.arg 1 2 3 key=value a=1

Execution modules are also available to salt runners:

.. code-block:: python

    __salt__['salt.cmd'](fun=fun, args=args, kwargs=kwargs)

'''
# import python libs
from __future__ import absolute_import, print_function, unicode_literals
import copy
import logging

# import salt libs
import salt.client
import salt.loader
import salt.pillar
import salt.utils.args
from salt.exceptions import SaltClientError

log = logging.getLogger(__name__)  # pylint: disable=invalid-name


def cmd(fun, *args, **kwargs):
    '''
    .. versionchanged:: Oxygen
        Added ``with_pillar`` argument

    Execute ``fun`` with the given ``args`` and ``kwargs``.  Parameter ``fun``
    should be the string :ref:`name <all-salt.modules>` of the execution module
    to call.

    .. note::
        Execution modules will be loaded *every time* this function is called.
        Additionally, keep in mind that since runners execute on the master,
        custom execution modules will need to be synced to the master using
        :py:func:`salt-run saltutil.sync_modules
        <salt.runners.saltutil.sync_modules>`, otherwise they will not be
        available.

    with_pillar : False
        If ``True``, pillar data will be compiled for the master

        .. note::
            To target the master in pillar data, keep in mind that the
            default ``id`` for the master is ``<hostname>_master``. This can be
            overridden by setting an ``id`` configuration parameter in the
            master config file.

    CLI example:

    .. code-block:: bash

        salt-run salt.cmd test.ping
        # call functions with arguments and keyword arguments
        salt-run salt.cmd test.arg 1 2 3 a=1
        salt-run salt.cmd mymod.myfunc with_pillar=True
    '''
    log.debug('Called salt.cmd runner with minion function %s', fun)

    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    with_pillar = kwargs.pop('with_pillar', False)

    opts = copy.deepcopy(__opts__)
    opts['grains'] = salt.loader.grains(opts)

    if with_pillar:
        opts['pillar'] = salt.pillar.get_pillar(
            opts,
            opts['grains'],
            opts['id'],<commit_msg>Clarify docstring<commit_after># -*- coding: utf-8 -*-
'''
This runner makes Salt's
execution modules available
on the salt master.

.. versionadded:: 2016.11.0

.. _salt_salt_runner:

Salt's execution modules are normally available
on the salt minion. Use this runner to call
execution modules on the salt master.
Salt :ref:`execution modules <writing-execution-modules>`
are the functions called by the ``salt`` command.

Execution modules can be called with ``salt-run``:

.. code-block:: bash

    salt-run salt.cmd test.ping
    # call functions with arguments and keyword arguments
    salt-run salt.cmd test.arg 1 2 3 key=value a=1

Execution modules are also available to salt runners:

.. code-block:: python

    __salt__['salt.cmd'](fun=fun, args=args, kwargs=kwargs)

'''
# import python libs
from __future__ import absolute_import, print_function, unicode_literals
import copy
import logging

# import salt libs
import salt.client
import salt.loader
import salt.pillar
import salt.utils.args
from salt.exceptions import SaltClientError

log = logging.getLogger(__name__)  # pylint: disable=invalid-name


def cmd(fun, *args, **kwargs):
    '''
    .. versionchanged:: Oxygen
        Added ``with_pillar`` argument

    Execute ``fun`` with the given ``args`` and ``kwargs``.  Parameter ``fun``
    should be the string :ref:`name <all-salt.modules>` of the execution module
    to call.

    .. note::
        Execution modules will be loaded *every time* this function is called.
        Additionally, keep in mind that since runners execute on the master,
        custom execution modules will need to be synced to the master using
        :py:func:`salt-run saltutil.sync_modules
        <salt.runners.saltutil.sync_modules>`, otherwise they will not be
        available.

    with_pillar : False
        If ``True``, pillar data will be compiled for the master

        .. note::
            To target the master in the pillar top file, keep in mind that the
            default ``id`` for the master is ``<hostname>_master``. This can be
            overridden by setting an ``id`` configuration parameter in the
            master config file.

    CLI example:

    .. code-block:: bash

        salt-run salt.cmd test.ping
        # call functions with arguments and keyword arguments
        salt-run salt.cmd test.arg 1 2 3 a=1
        salt-run salt.cmd mymod.myfunc with_pillar=True
    '''
    log.debug('Called salt.cmd runner with minion function %s', fun)

    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    with_pillar = kwargs.pop('with_pillar', False)

    opts = copy.deepcopy(__opts__)
    opts['grains'] = salt.loader.grains(opts)

    if with_pillar:
        opts['pillar'] = salt.pillar.get_pillar(
            opts,
            opts['grains'],
            opts['id'],
{'fraction_non_alphanumeric': 0.09736091298145506, 'fraction_numerical': 0.005706134094151213, 'mean_word_length': 2.9893314366998576, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2184550', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1548, 'n_words': 588}