Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAQ: it *is* possible to run pylint automatically #9959

Closed
edreamleo opened this issue Sep 24, 2024 · 2 comments · Fixed by #9960
Closed

FAQ: it *is* possible to run pylint automatically #9959

edreamleo opened this issue Sep 24, 2024 · 2 comments · Fixed by #9960
Labels
Documentation 📗 Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@edreamleo
Copy link
Contributor

edreamleo commented Sep 24, 2024

Bug description

This section of the FAQ is misleading.

Sure, running pylint on each keystroke is out of the question. But this Leo PR demonstrates that IDE's can lint files (in the background!) when Leo writes a changed file.

IDE code to run pylint in the background when saving changed files

# This is all Leo (IDE) code. There is no great need to understand it.

def run_pylint(self, fn: str, p: Position) -> None:
    """Run pylint on fn with the given pylint configuration file."""
    c, rc_fn = self.c, self.rc_fn

    # Invoke pylint directly.
    is_win = sys.platform.startswith('win')
    args = ','.join([f"'--rcfile={rc_fn}'", f"'{fn}'"])
    if is_win:
        args = args.replace('\\', '\\\\')
    command = (
        f'{sys.executable} -c "from pylint import lint; args=[{args}]; lint.Run(args)"')
    if not is_win:
        command = shlex.split(command)  # type:ignore
    
    # Run the command using the BPM.
    bpm = g.app.backgroundProcessManager
    bpm.start_process(c, command, fn=fn, kind='pylint')

Pylint output

Leo outputs pylint messages in Leo's log pane.
The user can click on the links to go to the correct Leo (outline) node.

Expected behavior

Revise these words in the FAQ:

I want to use pylint on each keystroke in my IDE, how can I do that ?

Don't do it: pylint's full suite of checks is not fast enough for that and never will be. pylint is best suited for linting on save for small projects, or for a continuous integration job or a git pre-push hook for big projects. The larger your repository is, the slower pylint will be.

If you want to make pylint faster for this type of use case, you can use the --errors-only option, which will remove all the refactor, convention, and warning checks. You can also disable checks with inherently high complexity that need to analyse the full code base like duplicate-code or cyclic-import (this list is not exhaustive).

Pylint version, platform, etc.

Not applicable.

@edreamleo edreamleo added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 24, 2024
@Pierre-Sassoulas Pierre-Sassoulas added Documentation 📗 Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 24, 2024
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue. We might add something to the tune of "unless a lot of work is done by your IDE to accommodate pylint", feel free to open a PR to modify the doc here:

pylint/doc/faq.rst

Lines 70 to 91 in 83cc31c

I want to use pylint on each keystroke in my IDE, how can I do that ?
---------------------------------------------------------------------
Don't do it: pylint's full suite of checks is not fast enough for that and never
will be. pylint is best suited for linting on save for small projects, or for a continuous
integration job or a git ``pre-push`` hook for big projects. The larger your repository
is, the slower pylint will be.
If you want to make pylint faster for this type of use case, you can use the ``--errors-only``
option, which will remove all the refactor, convention, and warning checks. You can also disable
checks with inherently high complexity that need to analyse the full code base like
``duplicate-code`` or ``cyclic-import`` (this list is not exhaustive).
Why do I have non-deterministic results when I try to parallelize pylint ?
--------------------------------------------------------------------------
pylint should analyse all your code at once in order to best infer the
actual values that result from calls. If only some of the files are given, pylint might
miss a particular value's type and produce inferior inference for the subset. Parallelization
of pylint is not easy; we also discourage the use of the ``-j`` option if this matters to you.

@edreamleo
Copy link
Contributor Author

@Pierre-Sassoulas I'll give it a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📗 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants