Permanent Config File in Pylint

有些话、适合烂在心里 提交于 2019-12-01 11:07:43

问题


I've setup a custom configuration file for Pylint (name, conveniently, config). There has to be a way that I don't have to include --rcfile=config on every run. How can I set the config file permanently?


回答1:


set the path to that file in the PYLINTRC environment variable, or rename the file $HOME/.pylintrc or /etc/pylintrc (the latter is probably only supported on *nix)




回答2:


When you do not specify the --rcfile option, 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

Thus depending on the method you choose, Pylint can use a different configuration file based on the location of the code, the user or the machine.

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.

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/7665579/permanent-config-file-in-pylint

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