KevinG
KevinG

Reputation: 956

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

I am trying to use CircleCI to run a pre-commit hook that runs pylint for both Python 2.7 and 3.7.

.circleci/config.yml runs pre-commit for both Python 2 and 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, among other things, runs pylint:

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

The problem here is that there is no version of pylint that is compatible with both Python 2.7 and 3.7: Python 2.7 requires pylint 1.x and Python 3.7 requires pylint 2.x.

How can I make Circle CI run both linting jobs using different versions of pylint?

I am considering several options:

Upvotes: 1

Views: 1204

Answers (1)

anthony sottile
anthony sottile

Reputation: 70223

The easiest option is probably to install both python2 and python3 though it is possible to use multiple configuration files to accomplish what you want:

Another option would be to only run one of them during CI by utilizing the --config option

With this you would have your default .pre-commit-config.yaml and a special .pre-commit-config-py27.yaml which includes the python2.7 pylint instead of the python3 pylint

In CI you'd invoke pre-commit run --config .pre-commit-config-py27.yaml --all-files --show-diff-on-failure for python2.7 and the normal pre-commit run --all-files --show-diff-on-failure for the non-py27 run

Upvotes: 3

Related Questions