Skip to content

Commit

Permalink
Allow passing arguments if epylint entry point is used as function (
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Dec 31, 2021
1 parent cf17a45 commit db0060a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 8 additions & 5 deletions pylint/epylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import sys
from io import StringIO
from subprocess import PIPE, Popen
from typing import Optional, Sequence


def _get_env():
Expand Down Expand Up @@ -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__":
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pylint_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit db0060a

Please sign in to comment.