pre-commit: pre-commit hook with language version language_version: python2.7 is not working

describe your issue

Getting attached error. I am on Mac OS, M1 machine

pyenv global system 2.7.18 3.8.5

Tried after clean cache using pre-comple clean as well. Using language version of python3 is not an option.

pre-commit --version

2.15.0

.pre-commit-config.yaml

default_stages: [commit]
repos:
  - repo: https://gitlab.com/pycqa/flake8
    rev: 3.9.2
    hooks:
      - id: flake8
        name: Flake8 (Python 2)
        language_version: python2.7
        exclude: |
          (?x)^(
            node_modules/.*|
            org/rpc/external/temporal_grpc/bin/.*
          )$

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 2.15.0
sys.version:
    3.9.7 (default, Sep  3 2021, 12:37:55)
    [Clang 12.0.5 (clang-1205.0.22.9)]
sys.executable: /usr/local/Cellar/pre-commit/2.15.0/libexec/bin/python3.9
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/Users/manishsharma/.cache/pre-commit/repoba54ew84/py_env-python2.7/bin/python', '-mpip', 'install', '.')
return code: -9
expected return code: 0
stdout: (none)
stderr: (none)
Traceback (most recent call last):
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/main.py", line 396, in main
    return run(args.config, store, args)
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/commands/run.py", line 417, in run
    install_hook_envs(to_install, store)
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 224, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/repository.py", line 82, in _hook_install
    lang.install_environment(
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/languages/python.py", line 205, in install_environment
    helpers.run_setup_cmd(prefix, install_cmd)
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/languages/helpers.py", line 52, in run_setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/usr/local/Cellar/pre-commit/2.15.0/libexec/lib/python3.9/site-packages/pre_commit/util.py", line 154, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/Users/manishsharma/.cache/pre-commit/repoba54ew84/py_env-python2.7/bin/python', '-mpip', 'install', '.')
return code: -9
expected return code: 0
stdout: (none)
stderr: (none)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (12 by maintainers)

Most upvoted comments

Ok. Here is what I did 1> Uninstall pre-commit from brew 2> create python3+ virtualenv for pre-commit and set path for pre-commit in virtualenv to be used. 3> Installed pre-commit and pre-push hooks

Looks good so far. Thanks a lot.