Pro*_*o Q 6 python pylint python-3.x pylintrc
我按照这些说明如何让 pylint 使用init-hook.
但是,当我运行终端命令时,pylint server.py --rcfile=../.pylintrc我得到了TypeError: expected str, bytes or os.PathLike object, not NoneType. (我认为这是因为找到 rcfile 的部分init-hook在某种程度上失败了,但我不确定。)
这是我的.pylintrc文件直至相关部分(其余部分只是默认模板):
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
# Specify a score threshold to be exceeded before program exits with error.
fail-under=10.0
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
# THIS GIVES THE ERROR
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
# THIS GIVES THE SAME ERROR
# init-hook="import os, sys, pylint; sys.path.append(os.path.join(os.path.dirname(pylint.config.PYLINTRC), 'platform'))"
Run Code Online (Sandbox Code Playgroud)
如何让这个 init-hook 代码正常工作?
我遇到了类似的问题,但我不想使用init-hook,因为我必须添加绝对路径,所以我找到了此处提供的不同解决方案,我将在此处包含该解决方案,但引用的链接包含更多上下文。
pylint版本3.0.3不再find_pylintrc存在。init-root.我的解决方案是将以下代码片段添加到文件MAIN的部分pylintrc。MAIN(如果您使用不同版本的 ,您可能会得到不同的东西pylint)。
[MAIN]
source-roots=repository/apps,src/apps
Run Code Online (Sandbox Code Playgroud)
源根目录列表可以是绝对的,也可以是相对于被pylint调用位置的工作文件夹的,或者是项目根文件夹(以防pylint从 IDE 中调用)。
| 归档时间: |
|
| 查看次数: |
6339 次 |
| 最近记录: |