Skip to content

Commit 45a586c

Browse files
Burst run into user guide and dev guide
1 parent 9c3a2fc commit 45a586c

File tree

3 files changed

+84
-85
lines changed

3 files changed

+84
-85
lines changed

doc/development_guide/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Development
88

99
contribute
1010
testing
11+
run
1112
profiling

doc/development_guide/run.rst

+83
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/user_guide/run.rst

-85
Original file line numberDiff line numberDiff line change
@@ -37,91 +37,6 @@ By default, pylint will exit with an error when one of the arguments is a direct
3737
a python package. In order to run pylint over all modules and packages within the provided
3838
subtree of a directory, the ``--recursive=y`` option must be provided.
3939

40-
For more details on this see the :ref:`faq`.
41-
42-
From another python program
43-
---------------------------
44-
45-
It is also possible to call Pylint from another Python program,
46-
thanks to the ``Run()`` function in the ``pylint.lint`` module
47-
(assuming Pylint options are stored in a list of strings ``pylint_options``) as:
48-
49-
.. sourcecode:: python
50-
51-
import pylint.lint
52-
pylint_opts = ['--disable=line-too-long', 'myfile.py']
53-
pylint.lint.Run(pylint_opts)
54-
55-
Another option would be to use the ``run_pylint`` function, which is the same function
56-
called by the command line. You can either patch ``sys.argv`` or supply arguments yourself:
57-
58-
.. sourcecode:: python
59-
60-
import pylint
61-
62-
sys.argv = ["pylint", "your_file"]
63-
pylint.run_pylint()
64-
# Or:
65-
pylint.run_pylint(argv=["your_file"])
66-
67-
To silently run Pylint on a ``module_name.py`` module,
68-
and get its standard output and error:
69-
70-
.. sourcecode:: python
71-
72-
from pylint import epylint as lint
73-
74-
(pylint_stdout, pylint_stderr) = lint.py_run('module_name.py', return_std=True)
75-
76-
It is also possible to include additional Pylint options in the first argument to ``py_run``:
77-
78-
.. sourcecode:: python
79-
80-
from pylint import epylint as lint
81-
82-
(pylint_stdout, pylint_stderr) = lint.py_run('module_name.py --disable C0114', return_std=True)
83-
84-
The options ``--msg-template="{path}:{line}: {category} ({msg_id}, {symbol}, {obj}) {msg}"`` and
85-
``--reports=n`` are set implicitly inside the ``epylint`` module.
86-
87-
Finally, it is possible to invoke pylint programmatically with a
88-
reporter initialized with a custom stream:
89-
90-
.. sourcecode:: python
91-
92-
from io import StringIO
93-
94-
from pylint.lint import Run
95-
from pylint.reporters.text import TextReporter
96-
97-
pylint_output = StringIO() # Custom open stream
98-
reporter = TextReporter(pylint_output)
99-
Run(["test_file.py"], reporter=reporter, do_exit=False)
100-
print(pylint_output.getvalue()) # Retrieve and print the text report
101-
102-
The reporter can accept any stream object as as parameter. In this example,
103-
the stream outputs to a file:
104-
105-
.. sourcecode:: python
106-
107-
from pylint.lint import Run
108-
from pylint.reporters.text import TextReporter
109-
110-
with open("report.out", "w") as f:
111-
reporter = TextReporter(f)
112-
Run(["test_file.py"], reporter=reporter, do_exit=False)
113-
114-
This would be useful to capture pylint output in an open stream which
115-
can be passed onto another program.
116-
117-
If your program expects that the files being linted might be edited
118-
between runs, you will need to clear pylint's inference cache:
119-
120-
.. sourcecode:: python
121-
122-
from pylint.lint import pylinter
123-
pylinter.MANAGER.clear_cache()
124-
12540

12641
Command line options
12742
--------------------

0 commit comments

Comments
 (0)