<commit_before>##
# Copyright (c) 2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import contextlib
import os
import imp
from semantix.utils.functional import contextlib as sx_contextlib
from semantix.utils import shell, helper


class RunCommand(shell.Command, name='run', expose=True):
    def get_parser(self, subparsers, **kwargs):
        parser = super().get_parser(subparsers, description='Run python script in semantix context.')

        parser.add_argument('-C', '--config', dest='configs', nargs='*',
                            help="configuration objects to load in specified order")
        parser.add_argument('--callable', dest='callable', default='main',
                            help='name of function/callable to execute, default to "main(*args)"')
        parser.add_argument('file', help=('path to a python script to be executed'))
        parser.add_argument('--with-debug-logger', dest='debug_logger',
                            action='store_true', default=False,
                            help='installs a debug logger that dumps semantix errors to stdout')
        parser.add_argument('args', nargs='*', help='script arguments')

        return parser

    def __call__(self, args):
        path = os.path.abspath(args.file)

        if not os.path.exists(path):
            raise ValueError('path not found: %r' % path)

        mod_name = os.path.splitext(os.path.split(path)[-1])[0]
        mod = imp.load_source(mod_name, path)
<commit_msg>utils.shell.run: Make sure multiple --config options are supported properly<commit_after>##
# Copyright (c) 2011 Sprymix Inc.
# All rights reserved.
#
# See LICENSE for details.
##


import contextlib
import os
import imp
from semantix.utils.functional import contextlib as sx_contextlib
from semantix.utils import shell, helper


class RunCommand(shell.Command, name='run', expose=True):
    def get_parser(self, subparsers, **kwargs):
        parser = super().get_parser(subparsers, description='Run python script in semantix context.')

        parser.add_argument('-C', '--config', dest='configs', action='append',
                            help="configuration objects to load in specified order")
        parser.add_argument('--callable', dest='callable', default='main',
                            help='name of function/callable to execute, default to "main(*args)"')
        parser.add_argument('file', help=('path to a python script to be executed'))
        parser.add_argument('--with-debug-logger', dest='debug_logger',
                            action='store_true', default=False,
                            help='installs a debug logger that dumps semantix errors to stdout')
        parser.add_argument('args', nargs='*', help='script arguments')

        return parser

    def __call__(self, args):
        path = os.path.abspath(args.file)

        if not os.path.exists(path):
            raise ValueError('path not found: %r' % path)

        mod_name = os.path.splitext(os.path.split(path)[-1])[0]
        mod = imp.load_source(mod_name, path)

{'fraction_non_alphanumeric': 0.12296681847755368, 'fraction_numerical': 0.003903708523096942, 'mean_word_length': 2.8776796973518284, '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': '339582', 'n_tokens_mistral': 874, 'n_tokens_neox': 851, 'n_words': 240}