在Docker映像上的预提交钩子中,为python 2.7和3.7运行pylint

在Docker映像上的预提交钩子中,为python 2.7和3.7运行pylint,python,pylint,pre-commit.com,Python,Pylint,Pre Commit.com,我试图使用CircleCI运行一个预提交钩子,该钩子在Python2.7和3.7中都运行pylint .circleci/config.yml为Python 2和Python 3运行预提交: jobs: lint-py2: docker: - image: python:2.7.14 steps: {snip} - run: pre-commit run --all-files {snip} lint-py3: d

我试图使用CircleCI运行一个预提交钩子,该钩子在Python2.7和3.7中都运行pylint

.circleci/config.yml
为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}
预提交(pre-commit)运行pylint:

-   repo: https://github.com/pre-commit/mirrors-pylint
    rev: v2.3.1  # Which version here?
    hooks:
    -   id: pylint
这里的问题是:Python2.7需要pylint 1.x,Python3.7需要pylint 2.x

如何使Circle CI使用不同版本的pylint运行两个linting作业

我正在考虑几种选择:

  • 在预提交配置中添加两次pylint(使用不同的别名),并在作业定义中添加一个或另一个
    • 在查看
      SKIP
      变量之前,pre-commit似乎会尝试安装依赖项,因此Python 2.7运行无论如何都会尝试安装pylint 2,错误为
      ERROR:找不到满足要求的版本pylint==2.3.1(来自pre-commit dummy package==0.0.0)
  • 使用同时具有Python版本和钩子级别的Docker映像
    • 这需要建立我自己的Docker形象
  • 跳过其中一个皮林作业中的pylint
  • 放下2.7或3.7支架

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

另一个选项是在CI期间通过使用该选项仅运行其中一个

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

在CI中,您将调用python2.7的
预提交运行--config.pre-commit-config-py27.yaml--all files--show diff on failure
,以及非py27运行的正常
预提交运行--all files--show diff on failure