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

十年热恋 提交于 2019-11-27 15:59:49

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16266452/for-pylint-is-it-possible-to-have-a-different-pylintrc-file-for-each-eclipse-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!