Skip to content

Commit 3bf22d8

Browse files
[doc pre-commit integration] Details about known caveats of using multiple processes
Refs microsoft/vscode-pylint#454 Also add known caveats for custom parallization. Closes #9341 Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
1 parent cd70568 commit 3bf22d8

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ repos:
7777
entry: pylint
7878
language: system
7979
types: [python]
80+
# Not that problematic to run in parallel see Pre-commit
81+
# integration in the doc for details
82+
# require_serial: true
8083
args: ["-rn", "-sn", "--rcfile=pylintrc", "--fail-on=I"]
8184
exclude: tests(/\w*)*/functional/|tests/input|tests(/\w*)*data/|doc/
8285
# We define an additional manual step to allow running pylint with a spelling

doc/faq.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,28 @@ to not be included as default messages.
6767
You can see the plugin you need to explicitly :ref:`load in the technical reference
6868
<user_guide/checkers/extensions:optional checkers>`.
6969

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

doc/user_guide/installation/pre-commit-integration.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,28 @@
33
Pre-commit integration
44
======================
55

6-
``pylint`` can be used as a `pre-commit <https://pre-commit.com>`_ hook.
6+
``pylint`` can be used as a `pre-commit <https://pre-commit.com>`_ hook. We however
7+
discourage it as pylint -- due to its speed -- is more suited to a continuous integration
8+
job or a git ``pre-push`` hook, especially if your repository is large.
79

810
Since ``pylint`` needs to import modules and dependencies to work correctly, the
9-
hook only works with a local installation of ``pylint`` (in your environment).
11+
hook only works with a local installation of ``pylint`` (in your environment). It means
12+
it can't be used with ``pre-commit.ci``, and you will need to add the following to your
13+
``.pre-commit-config.yaml`` ::
14+
15+
.. sourcecode:: yaml
16+
17+
ci:
18+
skip: [pylint]
19+
20+
Another limitation is that pylint should analyse all your code at once in order to best infer the
21+
actual values that result from calls. If only some of the files are given, pylint might
22+
miss a particular value's type and produce inferior inference for the subset. Since pre-commit slices
23+
the files given to it in order to parallelize the processing, the result can be degraded.
24+
It can also be unexpectedly different when the file set changes because the new slicing can change
25+
the inference. Thus the ``require_serial`` option should be set to ``true`` if correctness and determinism
26+
are more important than parallelization to you.
27+
1028
If you installed ``pylint`` locally it can be added to ``.pre-commit-config.yaml``
1129
as follows:
1230

@@ -19,6 +37,7 @@ as follows:
1937
entry: pylint
2038
language: system
2139
types: [python]
40+
require_serial: true
2241
args:
2342
[
2443
"-rn", # Only display messages

doc/user_guide/usage/run.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Parallel execution
153153
It is possible to speed up the execution of Pylint. If the running computer
154154
has more CPUs than one, then the work for checking all files could be spread across all
155155
cores via Pylints's sub-processes.
156+
156157
This functionality is exposed via the ``-j`` command-line parameter.
157158
If the provided number is 0, then the total number of CPUs will be autodetected and used.
158159

@@ -164,6 +165,15 @@ This will spawn 4 parallel Pylint sub-process, where each provided module will
164165
be checked in parallel. Discovered problems by checkers are not displayed
165166
immediately. They are shown just after checking a module is complete.
166167

168+
You can also do your own parallelization by launching pylint multiple times on subsets
169+
of your files (like ``pre-commit`` with the default ``require_serial=false`` does).
170+
Be aware, though: pylint should analyse all your code at once in order to best infer
171+
the actual values that result from calls. If only some of the files are given, pylint
172+
might miss a particular value's type and produce inferior inference for the subset.
173+
It can also be unexpectedly different when the file set changes because the new
174+
slicing can change the inference. So, don't do this if correctness and determinism
175+
are important to you.
176+
167177
Exit codes
168178
----------
169179

0 commit comments

Comments
 (0)