_run.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 pylint.lint import Run as LintRun
  10. from pylint.reporters.base_reporter import BaseReporter
  11. from pylint.testutils.lint_module_test import PYLINTRC
  12. def _add_rcfile_default_pylintrc(args: list[str]) -> list[str]:
  13. """Add a default pylintrc with the rcfile option in a list of pylint args."""
  14. if not any("--rcfile" in arg for arg in args):
  15. args.insert(0, f"--rcfile={PYLINTRC}")
  16. return args
  17. class _Run(LintRun):
  18. """Like Run, but we're using an explicitly set empty pylintrc.
  19. We don't want to use the project's pylintrc during tests, because
  20. it means that a change in our config could break tests.
  21. But we want to see if the changes to the default break tests.
  22. """
  23. def __init__(
  24. self,
  25. args: Sequence[str],
  26. reporter: BaseReporter | None = None,
  27. exit: bool = True, # pylint: disable=redefined-builtin
  28. ) -> None:
  29. args = _add_rcfile_default_pylintrc(list(args))
  30. super().__init__(args, reporter, exit)