4812N/A
4812N/ARunning Pylint
4812N/A**************
4812N/A
4812N/A
4812N/AInvoking Pylint
4812N/A===============
4812N/A
4812N/APylint is meant to be called from the command line. The usage is
4812N/A
4812N/A pylint [options] module_or_package
4812N/A
4812N/AYou should give Pylint the name of a python package or module. Pylint
4812N/A"will not import" this package or module, though uses Python internals
4812N/Ato locate them and as such is subject to the same rules and
4812N/Aconfiguration. You should pay attention to your "PYTHONPATH", since it
4812N/Ais a common error to analyze an installed version of a module instead
4812N/Aof the development version.
4812N/A
4812N/AIt is also possible to analyze python files, with a few restrictions.
4812N/AThe thing to keep in mind is that Pylint will try to convert the file
4812N/Aname to a module name, and only be able to process the file if it
4812N/Asucceeds.
4812N/A
4812N/A pylint mymodule.py
4812N/A
4812N/Ashould always work since the current working directory is
4812N/Aautomatically added on top of the python path
4812N/A
4812N/A pylint directory/mymodule.py
4812N/A
4812N/Awill work if "directory" is a python package (i.e. has an __init__.py
4812N/Afile) or if "directory" is in the python path.
4812N/A
4812N/AFor more details on this see the Frequently Asked Questions.
4812N/A
4812N/AYou can also start a thin gui around Pylint (require tkinter) by
4812N/Atyping
4812N/A
4812N/A pylint-gui
4812N/A
4812N/AThis should open a window where you can enter the name of the package
4812N/Aor module to check, at Pylint messages will be displayed in the user
4812N/Ainterface.
4812N/A
4812N/AIt is also possible to call Pylint from an other python program,
4812N/Athanks to "py_run()" function in "epylint" module, assuming Pylint
4812N/Aoptions are stored in "pylint_options" string, as:
4812N/A
4812N/A from pylint import epylint as lint
4812N/A lint.py_run(pylint_options)
4812N/A
4812N/ATo silently run Pylint on a "module_name.py" module, and get its
4812N/Astandard output and error:
4812N/A
4812N/A from pylint import epylint as lint
4812N/A (pylint_stdout, pylint_stderr) = lint.py_run('module_name.py', return_std=True)
4812N/A
4812N/A
4812N/ACommand line options
4812N/A====================
4812N/A
4812N/AFirst of all, we have two basic (but useful) options.
4812N/A
4812N/A--version
4812N/A
4812N/Ashow program's version number and exit
4812N/A
4812N/A-h, --help
4812N/A
4812N/Ashow help about the command line options
4812N/A
4812N/APylint is architectured around several checkers. By default all
4812N/Acheckers are enabled. You can disable a specific checker or some of
4812N/Aits messages or messages categories by specifying "--disable=<id>". If
4812N/Ayou want to enable only some checkers or some message ids, first use "
4812N/A--disable=all" then "--enable=<id>" with <id> being a comma separated
4812N/Alist of checker names and message identifiers. See the list of
4812N/Aavailable features for a description of provided checkers with their
4812N/Afunctionalities. The "--disable" and "--enable" options can be used
4812N/Awith comma separated lists mixing checkers, message ids and categories
4812N/Alike "-d C,W,E0611,design"
4812N/A
4812N/AIt is possible to disable all messages with "--disable=all". This is
4812N/Auseful to enable only a few checkers or a few messages by first
4812N/Adisabling everything, and then re-enabling only what you need.
4812N/A
4812N/AEach checker has some specific options, which can take either a yes/no
4812N/Avalue, an integer, a python regular expression, or a comma separated
4812N/Alist of values (which are generally used to override a regular
4812N/Aexpression in special cases). For a full list of options, use "--help"
4812N/A
4812N/ASpecifying all the options suitable for your setup and coding
4812N/Astandards can be tedious, so it is possible to use a configuration
4812N/Afile to specify the default values. You can specify a configuration
4812N/Afile on the command line using the "--rcfile" option. Otherwise,
4812N/APylint searches for a configuration file in the following order and
4812N/Auses the first one it finds:
4812N/A
4812N/A1. "pylintrc" in the current working directory
4812N/A
4812N/A2. If the current working directory is in a Python module, Pylint
4812N/A searches up the hierarchy of Python modules until it finds a
4812N/A "pylintrc" file. This allows you to specify coding standards on a
4812N/A module-by-module basis. Of course, a directory is judged to be a
4812N/A Python module if it contains an "__init__.py" file.
4812N/A
4812N/A3. The file named by environment variable "PYLINTRC"
4812N/A
4812N/A4. if you have a home directory which isn't "/root":
4812N/A
4812N/A 1. ".pylintrc" in your home directory
4812N/A
4812N/A 2. ".config/pylintrc" in your home directory
4812N/A
4812N/A5. "/etc/pylintrc"
4812N/A
4812N/AThe "--generate-rcfile" option will generate a commented configuration
4812N/Afile on standard output according to the current configuration and
4812N/Aexit. This includes:
4812N/A
4812N/A* Any configuration file found as explained above
4812N/A
4812N/A* Options appearing before "--generate-rcfile" on the Pylint command
4812N/A line
4812N/A
4812N/AOf course you can also start with the default values and hand tune the
4812N/Aconfiguration.
4812N/A
4812N/AOther useful global options include:
4812N/A
4812N/A--ignore=<file[,file]>
4812N/A
4812N/AAdd <file> (may be a directory) to the black list. It should be a base
4812N/Aname, not a path. Multiple entries can be given, separated by comma.
4812N/A
4812N/A--persistent=y_or_n
4812N/A
4812N/APickle collected data for later comparisons.
4812N/A
4812N/A--output-format=<format>
4812N/A
4812N/ASelect output format (text, html, custom).
4812N/A
4812N/A--msg-template=<template>
4812N/A
4812N/AModifiy text output message template.
4812N/A
4812N/A--list-msgs
4812N/A
4812N/AGenerate pylint's messages.
4812N/A
4812N/A--full-documentation
4812N/A
4812N/AGenerate pylint's full documentation, in reST format.
4812N/A
4812N/A
4812N/AParallel execution
4812N/A==================
4812N/A
4812N/AIt is possible to speed up the execution of Pylint. If the running
4812N/Acomputer has more CPUs than one, then the files to be checked could be
4812N/Aspread on all processors to Pylint sub-processes. This functionality
4812N/Ais exposed via "-j" command line parameter. It takes a number of sub-
4812N/Aprocesses that should be spawned. If the provided number is 0 then the
4812N/Anumber of CPUs will be used. The default number of workers is 1.
4812N/A
4812N/AExample:
4812N/A
4812N/A pylint -j 4 mymodule1.py mymodule2.py mymodule3.py mymodule4.py
4812N/A
4812N/AThis will spawn 4 parallel Pylint sub-process, where each provided
4812N/Amodule will be checked in parallel. Discovered problems by checkers
4812N/Aare not displayed immediately. They are shown just after completing
4812N/Achecking a module.
4812N/A
4812N/AThere are some limitations in running checks in parallel in current
4812N/Aimplementation. It is not possible to use custom plugins (i.e. "--
4812N/Aload-plugins" option), nor it is not possible to use initialization
4812N/Ahooks (i.e. "--init-hook" option).