<commit_before>import os
import sys
from contextlib import contextmanager
from typing import Any, Dict, Iterator, List

from pylama.lint import Linter as BaseLinter  # type: ignore

from isort.exceptions import FileSkipped

from . import api


@contextmanager
def supress_stdout() -> Iterator[None]:
    stdout = sys.stdout
    with open(os.devnull, "w") as devnull:
        sys.stdout = devnull
        yield
        sys.stdout = stdout


class Linter(BaseLinter):  # type: ignore
    def allow(self, path: str) -> bool:
        """Determine if this path should be linted."""
        return path.endswith(".py")

    def run(self, path: str, **meta: Any) -> List[Dict[str, Any]]:
        """Lint the file. Return an array of error dicts if appropriate."""
        with supress_stdout():
            try:
                if not api.check_file(path, disregard_skip=False):
                    return [
                        {
                            "lnum": 0,
                            "col": 0,
                            "text": "Incorrectly sorted imports.",
                            "type": "ISORT",
                        }
                    ]
            except FileSkipped:
                pass

            return []
<commit_msg>process parameters passed to Linter.run(), usually via [pylama:isort] section in pylama.ini configuration file<commit_after>import os
import sys
from contextlib import contextmanager
from typing import Any, Dict, Iterator, List

from pylama.lint import Linter as BaseLinter  # type: ignore

from isort.exceptions import FileSkipped

from . import api


@contextmanager
def supress_stdout() -> Iterator[None]:
    stdout = sys.stdout
    with open(os.devnull, "w") as devnull:
        sys.stdout = devnull
        yield
        sys.stdout = stdout


class Linter(BaseLinter):  # type: ignore
    def allow(self, path: str) -> bool:
        """Determine if this path should be linted."""
        return path.endswith(".py")

    def run(self, path: str, params: Dict[str, Any] = None, **meta: Any) -> List[Dict[str, Any]]:
        """Lint the file. Return an array of error dicts if appropriate."""
        with supress_stdout():
            try:
                if not api.check_file(path, disregard_skip=False, **params or {}):
                    return [
                        {
                            "lnum": 0,
                            "col": 0,
                            "text": "Incorrectly sorted imports.",
                            "type": "ISORT",
                        }
                    ]
            except FileSkipped:
                pass

            return []

{'fraction_non_alphanumeric': 0.09705438066465256, 'fraction_numerical': 0.0015105740181268882, 'mean_word_length': 1.6569709127382146, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 9, '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': '5792434', 'n_tokens_mistral': 729, 'n_tokens_neox': 695, 'n_words': 228}