Validate python code with pylint.
This plugin requires Grunt ~0.4.1
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-pylint --save-dev
Note: Installation requires the python package manager pip
(and python
itself) to be in your $PATH
(installation instructions) (it does not however, require networking -- all dependencies are bundled with the source)
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-pylint');
If you're having issues with installing the package due to the postinstall step, you can use your own version of pylint. Set the environment variable GRUNT_PYLINT_SKIP_POSTINSTALL=yes
before installation, install pylint
in your environment, and set externalPylint: true
in the task.
In your project's Gruntfile, add a section named pylint
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
pylint: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
Type: String
or Array
Messages to disable, either by category (like C
for convention), by ID (like C0103
) or by symbolic name (like invalid-name
).
Type: String
or Array
Messages to enable, either by category, ID or symbolic name.
Type: Boolean
Default: false
Only report on error messages.
Type Boolean
Default: false
Use pylint modules from python interpreter in path.
Type: Boolean
Default: false
Never fail the task.
Type: String
or Array
Files or directories to ignore. Must be basenames, not paths.
Type: String
Python code to execute before running pylint. This will be executed in the same python interpreter as pylint, and can thus be used to modify the python path before execution, or similar.
Type: String
Default: "short"
A string specifying how to format the output messages. Should be a string something like this: {msg_id}, line {line}: {msg}
. This string will be formatted using regular new-style python formatting, see the documentation for this here: http://docs.python.org/2/library/string.html#format-specification-mini-language
Available fields you can insert into the output is:
msg_id
: The ID of the message, likeW0103
.abspath
: The absolute path to the module where the error was foundmodule
: The name of module, likepackage.my_module.py
.obj
: The name of the object where the error was found, like MyObject or my_func.line
: The line number of the error.column
: Column number of the error.path
: Path to the module with the error.msg
: The actual error message.C
: (capital C) The first letter of the message category.category
: The category of the message, either Info, Refactor, Convention, Warning, Error or Fatal.symbol
: The symbolic name of the message, likeunused-variable
forW0612
.
Some aliases also exist:
parseable
:"{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}"
(this is often the one supported by external tools that read pylint output)msvs
:"{path}({line}): [{msg_id}({symbol}){obj}] {msg}"
The format read by Visual Studio.short
:"line {line}: {msg} ({symbol})"
This is the default.
Type: String
A file to save the output to.
Type: String
Alternatives: text|colorized|json
Default: "colorized"
What format the output will be in. If set to json
the messageTemplate
will be ignored.
Type: String
A path to a rcfile to use. Messages to enable or disable given in options.enable
and options.disable
will override anything given in the rcfile.
Type: Boolean
Default: false
Whether to include a full report or just the messages.
Type: 'Boolean'
Default: false
Whether to print a score summary.
Type: String
A path to a virtualenv to use when linting.
In the simplest case, use all the default pylint options:
grunt.initConfig({
pylint: {
dist: {
src: 'mypackage',
}
}
})
In this example, use a rcfile to specify checks to enable and disable, with overrides for one package.
grunt.initConfig({
pylint: {
options: {
rcfile: '.pylintrc',
},
src_package: {
src: 'mypackage',
},
tests: {
src: 'test',
options: {
disable: 'missing-docstring',
}
}
},
})
The python dependencies of pylint is bundled with the package as published on npm, but is not present directly in the repository. Thus, to be able to contribute to this project, do the following:
- Fork the project
- Clone it locally
- Run
npm run devsetup
to download the python dependencies (requires pip) - Run
npm install
to install the node dependencies - Write a test if possible and fix the issue you're having
- Verify that tests pass with
grunt test
If you want to test your fixes in another project, do steps 1-3 and then run npm link <path-to-your-local-clone>
in the other project.
To ensure that the npm package works out of the box on all systems, the source distribution of the python dependencies are included and installed into tasks/lib by pip in the postinstall
phase. This means pip is required on the system installing the package, but that seems a fair assumption for python projects.
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code using Grunt.
Repackage of 2.0.0 without a bundled .python-version
.
Remove support for python2.7 and python 3.
Update bundled pylint to 2.3.1.
You can now set GRUNT_PYLINT_SKIP_POSTINSTALL=y
to work around installation issues.
Enable setting score
to show a code quality score.
Add compatibility with pip < 1.5
Update bundled pylint to 1.5.4
Make compatible with grunt 1.0
Add initHook option
Update bundled pylint to 1.4.1
Add support for python 3
Use python exec from virtualenv
Add option externalPylint and automate testing
Bump pylint to 1.1
Properly escape all color codes
Initial release.