<commit_before>"""
Execute a command locally
"""
import importlib.util
import json
import os
import sys

from termcolor import cprint

from .local_test import fancy_print
from .utils import env_manager
from .utils.findfunc import find_manifest
from .utils.lambda_manifest import LambdaManifest


def setup_parser(parser):
    parser.add_argument('function_name', type=str, help='the base name of the function')
    parser.add_argument('--payload', type=str, help='the payload function', default=None)


def import_lambda_function_from_file(path):
    spec = importlib.util.spec_from_file_location('the_lambda_function', path)
    module_ = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module_)
    return module_.lambda_handler


def run(args):
    payload = args.payload
    if payload is None:
        cprint("reading payload from stdin...", 'yellow')
        payload = json.loads(sys.stdin.read())
    else:
        with open(payload, 'r') as f:
            payload = json.load(f)<commit_msg>MKTR-13943 -- clarify help text<commit_after>"""
Execute a command locally
"""
import importlib.util
import json
import os
import sys

from termcolor import cprint

from .local_test import fancy_print
from .utils import env_manager
from .utils.findfunc import find_manifest
from .utils.lambda_manifest import LambdaManifest


def setup_parser(parser):
    parser.add_argument('function_name', type=str, help='the base name of the function')
    parser.add_argument('--payload', type=str, help="json-formatted params to send to the function", default=None)


def import_lambda_function_from_file(path):
    spec = importlib.util.spec_from_file_location('the_lambda_function', path)
    module_ = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module_)
    return module_.lambda_handler


def run(args):
    payload = args.payload
    if payload is None:
        cprint("reading payload from stdin...", 'yellow')
        payload = json.loads(sys.stdin.read())
    else:
        with open(payload, 'r') as f:
            payload = json.load(f)
{'fraction_non_alphanumeric': 0.09927710843373494, 'fraction_numerical': 0.0024096385542168677, 'mean_word_length': 4.203007518796992, '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': '6309887', 'n_tokens_mistral': 627, 'n_tokens_neox': 610, 'n_words': 170}