<commit_before>"""Run linters, process output and display results."""
import logging
import shlex
import subprocess
import sys
from itertools import chain
from multiprocessing import Pool

from yala.linters import (Isort, Pycodestyle, Pydocstyle, Pyflakes, Pylint,
                          RadonCC, RadonMI)

LOG = logging.getLogger(__name__)


class Main:
    """Parse all linters and aggregate results."""

    # We only need the ``run`` method.
    # pylint: disable=too-few-public-methods

    def __init__(self):
        """Extra arguments for all linters (path to lint)."""
        self._args = None

    def get_results(self, args):
        """Run linters in parallel and sort all results."""
        self._args = args
        linters = (Pylint(), Pycodestyle(), Pydocstyle(), Pyflakes(), Isort(),
                   RadonCC(), RadonMI())
        with Pool() as pool:
            linters_results = pool.map(self._parse_linter, linters)
        return sorted(chain.from_iterable(linters_results))

    def run(self, args):
        """Print results."""
        results = self.get_results(args)
        if results:
            print()
            for result in results:
                print(result)
            issue = 'issues' if len(results) > 1 else 'issue'
            sys.exit(f'\n:( {len(results)} {issue} found.')
        else:
            print('\n:) No issues found.')

    def _parse_linter(self, linter):
        """Run a linter and return its results."""
        cmd_str = ' '.join((linter.cmd, ' '.join(self._args)))
        cmd = shlex.shlex(cmd_str, posix=True, punctuation_chars=True)
        cmd = list(cmd)
        process = subprocess.run(cmd, stdout=subprocess.PIPE)
        LOG.info('Finished %s.', cmd_str)
        output = process.stdout.decode('utf-8')
        lines = (line for line in output.split('\n') if line)
        return list(linter.parse(lines))


def main():
    """Entry point for the console script."""
    logging.basicConfig(level=logging.INFO)
    extra_args = sys.argv[1:]
    Main().run(extra_args)<commit_msg>Fix args being split on commas<commit_after>"""Run linters, process output and display results."""
import logging
import shlex
import subprocess
import sys
from itertools import chain
from multiprocessing import Pool

from yala.linters import (Isort, Pycodestyle, Pydocstyle, Pyflakes, Pylint,
                          RadonCC, RadonMI)

LOG = logging.getLogger(__name__)


class Main:
    """Parse all linters and aggregate results."""

    # We only need the ``run`` method.
    # pylint: disable=too-few-public-methods

    def __init__(self):
        """Extra arguments for all linters (path to lint)."""
        self._args = None

    def get_results(self, args):
        """Run linters in parallel and sort all results."""
        self._args = args
        linters = (Pylint(), Pycodestyle(), Pydocstyle(), Pyflakes(), Isort(),
                   RadonCC(), RadonMI())
        with Pool() as pool:
            linters_results = pool.map(self._parse_linter, linters)
        return sorted(chain.from_iterable(linters_results))

    def run(self, args):
        """Print results."""
        results = self.get_results(args)
        if results:
            print()
            for result in results:
                print(result)
            issue = 'issues' if len(results) > 1 else 'issue'
            sys.exit(f'\n:( {len(results)} {issue} found.')
        else:
            print('\n:) No issues found.')

    def _parse_linter(self, linter):
        """Run a linter and return its results."""
        cmd_str = ' '.join((linter.cmd, ' '.join(self._args)))
        cmd = shlex.split(cmd_str)
        cmd = list(cmd)
        process = subprocess.run(cmd, stdout=subprocess.PIPE)
        LOG.info('Finished %s', ' '.join(cmd))
        output = process.stdout.decode('utf-8')
        lines = (line for line in output.split('\n') if line)
        return list(linter.parse(lines))


def main():
    """Entry point for the console script."""
    logging.basicConfig(level=logging.INFO)
    extra_args = sys.argv[1:]
    Main().run(extra_args)
{'fraction_non_alphanumeric': 0.1272549975621648, 'fraction_numerical': 0.0014627011214041932, 'mean_word_length': 2.5098374679213005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5672596', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1198, 'n_words': 348}