def get_sls_opts(opts, **kwargs):
    '''
    Return a copy of the opts for use, optionally load a local config on top
    '''
    opts = copy.deepcopy(opts)

    if 'localconfig' in kwargs:
        return salt.config.minion_config(kwargs['localconfig'], defaults=opts)

    if 'saltenv' in kwargs:
        saltenv = kwargs['saltenv']
        if saltenv is not None:
            if not isinstance(saltenv, six.string_types):
                saltenv = six.text_type(saltenv)
            if opts['lock_saltenv'] and saltenv != opts['saltenv']:
                raise CommandExecutionError(
                    'lock_saltenv is enabled, saltenv cannot be changed'
                )
            opts['saltenv'] = kwargs['saltenv']

    pillarenv = None
    if kwargs.get('pillarenv'):
        pillarenv = kwargs.get('pillarenv')
    if opts.get('pillarenv_from_saltenv') and not pillarenv:
        pillarenv = kwargs.get('saltenv')
    if pillarenv is not None and not isinstance(pillarenv, six.string_types):
        opts['pillarenv'] = six.text_type(pillarenv)
    else:
        opts['pillarenv'] = pillarenv

    return opts
Return a copy of the opts for use, optionally load a local config on top