如何让 pylint 使用 init-hook 正确导入我的文件

问题描述 投票:0回答:1

我按照 这些说明了解如何使用

init-hook
让 pylint 正确导入我的文件。

但是,当我运行终端命令

pylint server.py --rcfile=../.pylintrc
时,我得到
TypeError: expected str, bytes or os.PathLike object, not NoneType
。 (我认为这是因为
init-hook
找到 rcfile 的部分在某种程度上失败了,但我不确定。)

这是我的

.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'))"

我怎样才能让这个init-hook代码正常工作?

python python-3.x pylint pylintrc
1个回答
0
投票

我有类似的问题,但我不想使用

init-hook
,因为我必须添加绝对路径,所以我找到了here

© www.soinside.com 2019 - 2024. All rights reserved.