Tox:flake8 和 pylint 等工具的每个平台配置

kon*_*erw 2 python pylint tox flake8

我在 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
Run Code Online (Sandbox Code Playgroud)

问题是如何为工具(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'
Run Code Online (Sandbox Code Playgroud)

J.G*_*.G. 5

也许我错过了您要求的某些部分,但是运行flake8特定于平台的似乎非常简单:

[testenv]
platform =
    linux: linux
    windows: win

[testenv:flake8]
deps = flake8
commands =
    linux: flake8 <linux specific directories>
    windows: flake8 <windows specific directories>
Run Code Online (Sandbox Code Playgroud)

还可以与官方文档进行比较。