_run.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  2. # For details: https://github.com/pylint-dev/pylint/blob/main/LICENSE
  3. # Copyright (c) https://github.com/pylint-dev/pylint/blob/main/CONTRIBUTORS.txt
  4. """Classes and functions used to mimic normal pylint runs.
  5. This module is considered private and can change at any time.
  6. """
  7. from __future__ import annotations
  8. from collections.abc import Sequence
  9. from typing import Any
  10. from pylint.lint import Run as LintRun
  11. from pylint.lint.run import UNUSED_PARAM_SENTINEL
  12. from pylint.reporters.base_reporter import BaseReporter
  13. from pylint.testutils.lint_module_test import PYLINTRC
  14. def _add_rcfile_default_pylintrc(args: list[str]) -> list[str]:
  15. """Add a default pylintrc with the rcfile option in a list of pylint args."""
  16. if not any("--rcfile" in arg for arg in args):
  17. args.insert(0, f"--rcfile={PYLINTRC}")
  18. return args
  19. class _Run(LintRun):
  20. """Like Run, but we're using an explicitly set empty pylintrc.
  21. We don't want to use the project's pylintrc during tests, because
  22. it means that a change in our config could break tests.
  23. But we want to see if the changes to the default break tests.
  24. """
  25. def __init__(
  26. self,
  27. args: Sequence[str],
  28. reporter: BaseReporter | None = None,
  29. exit: bool = True, # pylint: disable=redefined-builtin
  30. do_exit: Any = UNUSED_PARAM_SENTINEL,
  31. ) -> None:
  32. args = _add_rcfile_default_pylintrc(list(args))
  33. super().__init__(args, reporter, exit, do_exit)