diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-12-31 13:51:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-31 13:51:30 +0100 |
commit | db0060a03a6b14f7ca7eb77ce028c6a660766866 (patch) | |
tree | 40d4cae4eaf26a1307c603d7704aa1891952b009 | |
parent | cf17a454ffb0b5ee47babfc537bdf782a1915da6 (diff) | |
download | pylint-git-db0060a03a6b14f7ca7eb77ce028c6a660766866.tar.gz |
Allow passing arguments if ``epylint`` entry point is used as function (#5616)
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | doc/whatsnew/2.13.rst | 2 | ||||
-rw-r--r-- | pylint/__init__.py | 8 | ||||
-rwxr-xr-x | pylint/epylint.py | 13 | ||||
-rw-r--r-- | tests/test_pylint_runners.py | 4 |
5 files changed, 19 insertions, 10 deletions
@@ -90,7 +90,7 @@ Release date: TBA Closes #5504 -* When invoking ``pylint``, ``symilar`` or ``pyreverse`` by importing them in a python file +* When invoking ``pylint``, ``epylint``, ``symilar`` or ``pyreverse`` by importing them in a python file you can now pass an ``arguments`` keyword besides patching ``sys.argv``. Closes #5320 diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index 5b16243cf..9db50635e 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -121,7 +121,7 @@ Other Changes Closes #5557 -* When invoking ``pylint``, ``symilar`` or ``pyreverse`` by importing them in a python file +* When invoking ``pylint``, ``epylint``, ``symilar`` or ``pyreverse`` by importing them in a python file you can now pass an ``arguments`` keyword besides patching ``sys.argv``. Closes #5320 diff --git a/pylint/__init__.py b/pylint/__init__.py index d758a0db0..16d81d903 100644 --- a/pylint/__init__.py +++ b/pylint/__init__.py @@ -31,10 +31,14 @@ def run_pylint(argv: Optional[Sequence[str]] = None): sys.exit(1) -def run_epylint(): +def run_epylint(argv: Optional[Sequence[str]] = None): + """Run epylint + + argv can be a list of strings normally supplied as arguments on the command line + """ from pylint.epylint import Run as EpylintRun - EpylintRun() + EpylintRun(argv) def run_pyreverse(argv: Optional[Sequence[str]] = None): diff --git a/pylint/epylint.py b/pylint/epylint.py index 98b11afd5..a7eec3302 100755 --- a/pylint/epylint.py +++ b/pylint/epylint.py @@ -64,6 +64,7 @@ import shlex import sys from io import StringIO from subprocess import PIPE, Popen +from typing import Optional, Sequence def _get_env(): @@ -185,15 +186,17 @@ def py_run(command_options="", return_std=False, stdout=None, stderr=None): return None -def Run(): - if len(sys.argv) == 1: +def Run(argv: Optional[Sequence[str]] = None): + if not argv and len(sys.argv) == 1: print(f"Usage: {sys.argv[0]} <filename> [options]") sys.exit(1) - elif not os.path.exists(sys.argv[1]): - print(f"{sys.argv[1]} does not exist") + + argv = argv or sys.argv[1:] + if not os.path.exists(argv[0]): + print(f"{argv[0]} does not exist") sys.exit(1) else: - sys.exit(lint(sys.argv[1], sys.argv[2:])) + sys.exit(lint(argv[0], argv[1:])) if __name__ == "__main__": diff --git a/tests/test_pylint_runners.py b/tests/test_pylint_runners.py index dbbea28db..88113cb2c 100644 --- a/tests/test_pylint_runners.py +++ b/tests/test_pylint_runners.py @@ -23,7 +23,9 @@ def test_runner(runner: Callable, tmpdir: LocalPath) -> None: assert err.value.code == 0 -@pytest.mark.parametrize("runner", [run_pylint, run_pyreverse, run_symilar]) +@pytest.mark.parametrize( + "runner", [run_epylint, run_pylint, run_pyreverse, run_symilar] +) def test_runner_with_arguments(runner: Callable, tmpdir: LocalPath) -> None: """Check the runners with arguments as parameter instead of sys.argv""" filepath = os.path.abspath(__file__) |