@@ -37,91 +37,6 @@ By default, pylint will exit with an error when one of the arguments is a direct
37
37
a python package. In order to run pylint over all modules and packages within the provided
38
38
subtree of a directory, the ``--recursive=y `` option must be provided.
39
39
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
-
125
40
126
41
Command line options
127
42
--------------------
0 commit comments