运行 python 2.7 和 3.7 的 pylint,在 Docker 图像上的预提交挂钩中

Run pylint for both python 2.7 and 3.7, in pre-commit hook on Docker image

我正在尝试将 CircleCI 用于 运行 预提交挂钩,运行s pylint 用于 Python 2.7 和 3.7。

.circleci/config.yml 运行s 预提交 Python 2 和 Python 3:

jobs:
  lint-py2:
    docker:
      - image: python:2.7.14
    steps:
      {snip}
      - run: pre-commit run --all-files
      {snip}

  lint-py3:
    docker:
      - image: python:3.7.3
    steps:
      {snip}
      - run: pre-commit run --all-files
      {snip}

预提交,除其他外,运行s pylint:

-   repo: https://github.com/pre-commit/mirrors-pylint
    rev: v2.3.1  # Which version here?
    hooks:
    -   id: pylint

这里的问题是 there is no version of pylint that is compatible with both Python 2.7 and 3.7:Python 2.7 需要 pylint 1.x 和 Python 3.7 需要 pylint 2.x.

如何使用不同版本的 pylint 使 Circle CI 运行 都成为 linting 作业?

我正在考虑几个选项:

最简单的选择可能是同时安装 python2 和 python3,尽管可以使用多个配置文件来完成您想要的:

另一种选择是在 CI 期间仅 运行 其中之一,方法是利用 --config 选项

有了这个,您将拥有默认的 .pre-commit-config.yaml 和一个特殊的 .pre-commit-config-py27.yaml,其中包括 python2.7 pylint 而不是 python3 pylint

在 CI 中,您将为 python2.7 调用 pre-commit run --config .pre-commit-config-py27.yaml --all-files --show-diff-on-failure,为非 py27 运行[=16= 调用正常的 pre-commit run --all-files --show-diff-on-failure ]