Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Pylint, is it possible to have a different pylintrc file for each Eclipse project?

I saw I can change it per Eclipse instance using this solution. I would like to set it per project. Is it possible?

like image 773
bandit Avatar asked Apr 28 '13 18:04

bandit


People also ask

What is Pylintrc file?

If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis.


2 Answers

This is not Eclipse specific, but it may help anyway. According to pylint command line options:

You can specify a configuration file on the command line using the --rcfile option. Otherwise, Pylint searches for a configuration file in the following order and uses the first one it finds:

  1. pylintrc in the current working directory
  2. .pylintrc in the current working directory
  3. If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an __init__.py file.
  4. The file named by environment variable PYLINTRC
  5. If you have a home directory which isn’t /root:
    1. .pylintrc in your home directory
    2. .config/pylintrc in your home directory
  6. /etc/pylintrc

Points 1 or 3 above may help.

like image 122
sthenault Avatar answered Oct 08 '22 02:10

sthenault


Simply put a configuration file named pylintrc (with no '.') in the root directory of each project. Pylint is run with the project directory as the current working directory, and this is the first place that pylint looks for a configuration file.

The PyDev documentation suggests naming the file .pylintrc, but this is less robust because ./.pylintrc is almost last in the order of places that pylint will search. The PyDev documentation further says that this only works for PyDev 2.8.0 and above, but I am using PyDev 2.6.0 and it works for me.

The search order for the configuration file in the other answer is not quite right. I just submitted an enhancement to the Pylint documentation that describes the configuration file search order correctly:

You can specify a configuration file on the command line using the --rcfile option. Otherwise, Pylint searches for a configuration file in the following order and uses the first one it finds:

  1. pylintrc in the current working directory
  2. If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an __init__.py file.
  3. The file named by environment variable PYLINTRC
  4. .pylintrc in your home directory, unless you have no home directory or your home directory is /root
  5. .pylintrc in the current working directory
  6. /etc/pylintrc

Note that the configuration file only applies to Python files that are in modules. Thus, Pylint still uses its default rules when analyzing Python files in a directory with no __init__.py file. Perhaps it is this problem that is fixed in PyDev 2.8.0.

For example, I have a bin/ directory containing command line applications. Ordinarily, this directory needs no __init__.py file because it is never imported. I had to add a bin/__init__.py file to get Pylint to analyze these Python files using my pylintrc file.

like image 5
John McGehee Avatar answered Oct 08 '22 02:10

John McGehee