Skip to content

Commit 43d01fa

Browse files
Burst run into user guide and dev guide
1 parent 38e37e6 commit 43d01fa

File tree

10 files changed

+266
-377
lines changed

10 files changed

+266
-377
lines changed

doc/developer_guide/technical_reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Technical Reference
88
:titlesonly:
99

1010
startup
11+
run
1112
custom_checkers
1213
plugins
1314
transform_plugins
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
===========================================
2+
Running Pylint from another python program
3+
===========================================
4+
5+
You can call Pylint from another Python program thanks to the ``Run()``
6+
function in the ``pylint.lint`` module
7+
(assuming Pylint options are stored in a list of strings ``pylint_options``) as:
8+
9+
.. sourcecode:: python
10+
11+
import pylint.lint
12+
pylint_opts = ['--disable=line-too-long', 'myfile.py']
13+
pylint.lint.Run(pylint_opts)
14+
15+
Another option would be to use the ``run_pylint`` function, which is the same function
16+
called by the command line. You can either patch ``sys.argv`` or supply arguments yourself:
17+
18+
.. sourcecode:: python
19+
20+
import pylint
21+
22+
sys.argv = ["pylint", "your_file"]
23+
pylint.run_pylint()
24+
# Or:
25+
pylint.run_pylint(argv=["your_file"])
26+
27+
To silently run Pylint on a ``module_name.py`` module,
28+
and get its standard output and error:
29+
30+
.. sourcecode:: python
31+
32+
from pylint import epylint as lint
33+
34+
(pylint_stdout, pylint_stderr) = lint.py_run('module_name.py', return_std=True)
35+
36+
It is also possible to include additional Pylint options in the first argument to ``py_run``:
37+
38+
.. sourcecode:: python
39+
40+
from pylint import epylint as lint
41+
42+
(pylint_stdout, pylint_stderr) = lint.py_run('module_name.py --disable C0114', return_std=True)
43+
44+
The options ``--msg-template="{path}:{line}: {category} ({msg_id}, {symbol}, {obj}) {msg}"`` and
45+
``--reports=n`` are set implicitly inside the ``epylint`` module.
46+
47+
Finally, it is possible to invoke pylint programmatically with a
48+
reporter initialized with a custom stream:
49+
50+
.. sourcecode:: python
51+
52+
from io import StringIO
53+
54+
from pylint.lint import Run
55+
from pylint.reporters.text import TextReporter
56+
57+
pylint_output = StringIO() # Custom open stream
58+
reporter = TextReporter(pylint_output)
59+
Run(["test_file.py"], reporter=reporter, do_exit=False)
60+
print(pylint_output.getvalue()) # Retrieve and print the text report
61+
62+
The reporter can accept any stream object as as parameter. In this example,
63+
the stream outputs to a file:
64+
65+
.. sourcecode:: python
66+
67+
from pylint.lint import Run
68+
from pylint.reporters.text import TextReporter
69+
70+
with open("report.out", "w") as f:
71+
reporter = TextReporter(f)
72+
Run(["test_file.py"], reporter=reporter, do_exit=False)
73+
74+
This would be useful to capture pylint output in an open stream which
75+
can be passed onto another program.
76+
77+
If your program expects that the files being linted might be edited
78+
between runs, you will need to clear pylint's inference cache:
79+
80+
.. sourcecode:: python
81+
82+
from pylint.lint import pylinter
83+
pylinter.MANAGER.clear_cache()

doc/exts/pylint_extensions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def builder_inited(app: Optional[Sphinx]) -> None:
4848

4949
extensions_doc = os.path.join(base_path, "doc", "user_guide", "extensions.rst")
5050
with open(extensions_doc, "w", encoding="utf-8") as stream:
51-
stream.write(
52-
get_rst_title("Optional Pylint checkers in the extensions module", "=")
53-
)
51+
stream.write(get_rst_title("Optional Checkers", "="))
5452
stream.write("Pylint provides the following optional plugins:\n\n")
5553
for module in modules:
5654
stream.write(f"- :ref:`{module}`\n")

doc/faq.rst

Lines changed: 0 additions & 270 deletions
This file was deleted.

doc/index.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ re-evaluate and re-enable messages as your priorities evolve.
4141
:titlesonly:
4242
:hidden:
4343

44-
intro
4544
user_guide/index.rst
4645
developer_guide/index.rst
47-
faq
4846
contact

0 commit comments

Comments
 (0)