【问题标题】:Can I set a custom "system root" path with pylint?我可以使用 pylint 设置自定义“系统根”路径吗?
【发布时间】:2021-07-14 12:55:03
【问题描述】:

我有一个构建系统,可以为嵌入式平台制作完整的系统映像。它包含大量的 Python 代码。目前,我正在使用在 qemu 下运行的目标平台的 Python 和 Pylint 对此进行检查,但速度很慢。真的很慢。

有没有办法运行构建平台的 linter,但使用目标树中的所有 Python 文件?

【问题讨论】:

  • 我不明白这个问题,“目标树中的python文件”是什么?您是否在所有系统的 python 文件上运行 pylint,即使是那些您没有编码的文件?
  • 我正在对我编写的文件运行 pylint,但 pylint 也对系统上安装的软件包执行各种操作,例如检查所有导入是否存在且正确。我希望根据我构建的目标文件系统检查这些,而不是我的构建机器上安装的包。
  • 换句话说,我在问一个问题,“如果我在嵌入式目标上安装 pylint 并在此代码上运行它,它会返回任何错误吗?”但我想在没有实际在嵌入式目标上安装 pylint 的情况下回答这个问题。

标签: python embedded pylint


【解决方案1】:

我不知道有任何内置方法可以做到这一点,但你可以:

  • 使用init_hook 选项,您可以修改sys.path 以指向您的嵌入式目标(或您可以在python 中执行的任何操作)。

  • 依靠您的测试(自动或手动)来检测错误,并一一禁用已知的误报,无论是对每个测试使用 pylint: disable=no-member 还是直接在配置中使用:

[TYPECHECK]

# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators=contextlib.contextmanager

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=REQUEST,
                  acl_users,
                  aq_parent

# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=SQLObject,optparse.Values,thread._local,_thread._local

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis). It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=

# List of decorators that change the signature of a decorated function.
signature-mutators=

【讨论】:

    猜你喜欢
    • 2011-12-21
    • 2012-06-30
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多