Pre-commit: Hook specifies language_version but is using language system problem when upgrading to 2.10.0

Created on 6 Feb 2021  路  4Comments  路  Source: pre-commit/pre-commit

After upgrading to 2.10.0 I am now facing a hard fail for hooks that are using system.

For instance:

The hook `black` specifies `language_version` but is using language `system` which does not install an environment.

This used to work fine in 2.9.3 which was my previous version.

My particular setup uses Pipenv, Django, Black, and Pylint.

Now my options are to use either python or python_venv, none of which actually work for me.

I tried to use additional_dependencies, which still doesn't work because pylint_django requires a configured Django project in order to load the configuration file and similar.

Is there a new way of doing this that I am not aware of? I've looked at the docs and can't figure this one out.

Please advise.

Pipfile:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
babel = "*"
bottlenose = "*"
django = "*"
django-anymail = { extras = ["mailgun"], version = "*" }
django-compressor = "*"
django-dynamic-preferences = "*"
django-environ = "*"
django-perms-provisioner = "*"
django-sass-processor = "*"
flask-cors = "*"
gunicorn = "*"
libsass = "*"
measurement = "*"
polib = "*"
psycopg2-binary = "*"
python-dateutil = "*"
pyyaml = "*"
sqlalchemy = "*"
timezones = "*"
whitenoise = { extras = ["brotli"], version = "*" }
rollbar = "*"

[dev-packages]
black = "~=20.8b1"
coverage = { extras = ["toml"], version = "*" }
install = "*"
invoke = "*"
pre-commit = "*"
pylint = "~=2.6"
pylint-django = "*"
skjold = "*"
wheel = "*"
faker = "*"

[requires]
python_version = "3.7"

[pipenv]
allow_prereleases = true

.pre-commit-config.yaml:

default_language_version:
  python: python3.7
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v3.2.0
    hooks:
      - id: trailing-whitespace
      - id: check-executables-have-shebangs
      - id: debug-statements
      - id: check-merge-conflict
      - id: name-tests-test
        args: ["--django"]

  - repo: https://github.com/psf/black
    rev: 20.8b1
    hooks:
      - id: black
        language: system
        args: ["--line-length=120"]

  - repo: https://github.com/pre-commit/mirrors-pylint
    rev: v2.3.1
    hooks:
      - id: pylint
        language: system
        args: ["--rcfile=pylintrc", "--load-plugins=pylint_django"]

  - repo: https://github.com/twu/skjold
    rev: v0.2.0
    hooks:
      - id: skjold

pyproject.toml:

[tool.black]
line-length = 120
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
/(
    \.git
  | \.venv
  | build
  | dist
)/
'''

[tool.skjold]
report_only = true
report_format = "json"
sources = ["pyup", "github", "gemnasium"]
cache_dir = ".skjold_cache"
cache_expires = 43200

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-s"
log_cli_level = "INFO"
testpaths = ["tests"]
filterwarnings = [
    "ignore::DeprecationWarning",
    "ignore::PendingDeprecationWarning",
    "ignore::UserWarning",
]
question

Most helpful comment

@asottile I am using the hook repositories because they provide the functionality out of the box so that I don't have to manually write the file matching and any other arguments into the pre-commit configuration file.

this is an intentional change because your configuration is misconfigured and was leading to confusion

How are we supposed to set up Python projects with Django and pylint to work properly with pre-commit in the future?

Use a repository local hook, as shown in the documentation (there's an example for pylint there). I would not suggest using language: system for black

All 4 comments

If you're using language: system then you're not installing a particular language -- there's no reason to use repo: ... for that, you probably want to use repo: local

in your case, you're inheriting language_version from the base repository

this is an intentional change because your configuration is misconfigured and was leading to confusion

@asottile I am using the hook repositories because they provide the functionality out of the box so that I don't have to manually write the file matching and any other arguments into the pre-commit configuration file.

this is an intentional change because your configuration is misconfigured and was leading to confusion

How are we supposed to set up Python projects with Django and pylint to work properly with pre-commit in the future?

@asottile I am using the hook repositories because they provide the functionality out of the box so that I don't have to manually write the file matching and any other arguments into the pre-commit configuration file.

this is an intentional change because your configuration is misconfigured and was leading to confusion

How are we supposed to set up Python projects with Django and pylint to work properly with pre-commit in the future?

Use a repository local hook, as shown in the documentation (there's an example for pylint there). I would not suggest using language: system for black

@asottile awesome, thank you for this. My configuration now works great with pre-commit again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ymyke picture ymyke  路  4Comments

ustun picture ustun  路  5Comments

gretel picture gretel  路  5Comments

zmitchell picture zmitchell  路  3Comments

DaveParr picture DaveParr  路  4Comments