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

问题描述

我在 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'

解决方法

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

[testenv]
platform =
    linux: linux
    windows: win

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

还要与 official documentation 进行比较。