我正在尝试使用 CircleCI 运行一个预提交挂钩,该挂钩为 Python 2.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}
除其他外,预提交运行 pylint:
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v2.3.1 # Which version here?
hooks:
- id: pylint
这里的问题是没有与 Python 2.7 和 3.7 兼容的 pylint 版本:Python 2.7 需要 pylint 1.x,而 Python 3.7 需要 pylint 2.x。
如何让 Circle CI 使用不同版本的 pylint 运行两个 linting 作业?
我正在考虑几种选择:
- 在预提交配置中添加 pylint 两次(使用不同的别名)并在作业定义中
禁用其中一个或另一个
- 似乎 pre-commit在查看变量之前
SKIP
尝试安装依赖项,因此 Python 2.7 运行无论如何都会尝试安装 pylint 2,并且出现错误ERROR: Could not find a version that satisfies the requirement pylint==2.3.1 (from pre-commit-dummy-package==0.0.0)
- 似乎 pre-commit在查看变量之前
- 使用具有两个 Python 版本的 Docker 映像,并在钩子级别
设置 Python 版本
- 这需要构建我自己的 Docker 镜像
- 在其中一项 linting 工作中跳过 pylint
- 放弃 2.7 或 3.7 支持