【问题标题】:Tox: per-platform configuration for tools like flake8 and pylintTox:针对 flake8 和 pylint 等工具的每个平台配置
【发布时间】:2021-04-01 08:12:20
【问题描述】:

我在 linux 和 windows 环境中都有用于 ci 的 tox.ini 配置,类似这样:

[tox]
envlist =
    {py3,py27}-{test,lint}-{linux,windows}
    flake8
    check-package
skip_missing_interpreters = true
isolated_build = True
distdir = dist

[testenv]
platform =
    linux: linux
    windows: win

# Reuse py3 and py27 envs for pylint
envdir =
    py3: {toxworkdir}/py3
    py27: {toxworkdir}/py27
    !py3-!py27: {toxworkdir}/{envname}
deps =
    py27: setuptools < 45.0.0

# test extras must include pytest and pylint
extras = test
commands =
    test: python -m pytest -c {toxinidir}/pytest.ini --junitxml=test-reports/pytest.{envname}.xml {posargs}
    lint: python -m pylint --rcfile=tox.ini src/displaylink {posargs}

[testenv:flake8]
basepython = python3
skip_install = true
deps = flake8
commands = flake8 src tests

[tool:pylint]
disable = missing-docstring,
          R,
          C,
          line-too-long
output-format = parseable
reports = no
extension-pkg-whitelist = win32api, win32gui

[flake8]
ignore = E501, E722, W503
per-file-ignores =
    # imported but unused
    __init__.py: F401
max-complexity = 10

问题是如何为工具(flake 和 pylint)添加每个平台的配置?我需要从 flake8 中排除文件/目录,并且 pylint 运行取决于操作系统,即我有 windows 子目录,其中的文件不会在 linux 上通过 linting,反之亦然

编辑:

我在 linux 上遇到的 pylint 错误示例:

py3-lint-linux run-test: commands[0] | python -m pylint --rcfile=tox.ini src/displaylink

************* Module displaylink.qa.windows.registry
registry.py:4: [E0401(import-error), ] Unable to import 'win32con'
registry.py:74: [E0602(undefined-variable), reg_value_exists] Undefined variable 'WindowsError'
registry.py:82: [E0602(undefined-variable), reg_key_exists] Undefined variable 'WindowsError'

【问题讨论】:

  • 您好,我是 tox 的维护者/作者。注意不支持共享(重用您的评论制定方式)毒药环境,您很可能会遇到麻烦。您可以使用平台因素使命令的某些部分依赖于平台。
  • 平台特定... linting ?什么样的东西会改变基于平台的静态分析?

标签: python pylint tox flake8


【解决方案1】:

也许我错过了您的某些要求,但运行 flake8 平台特定似乎很简单:

[testenv]
platform =
    linux: linux
    windows: win

[testenv:flake8]
deps = flake8
commands =
    linux: flake8 <linux specific directories>
    windows: flake8 <windows specific directories>

还可以与official documentation 进行比较。

【讨论】:

  • 我希望可以在[flake8][tool:pylint] 下更改配置,但修改命令行似乎已经足够了;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-07
  • 1970-01-01
  • 1970-01-01
  • 2016-12-11
  • 2011-01-19
  • 2013-11-20
  • 1970-01-01
相关资源
最近更新 更多