question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:26 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
manishsharma64commented, Sep 28, 2021

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.

0reactions
stuertzcommented, Jan 14, 2022

I wasn’t able to reproduce the metioned solution and digged a little deeper into this. It looks like this is more an issue with python3 virtualenv creating a python2 env.

see

Read more comments on GitHub >

github_iconTop Results From Across the Web

git - Use pre-commit hook for black with multiple language ...
one way would be to set language_version: python3 (this used to be the default for black ) -- the actual language_version you use...
Read more >
pre-commit
A framework for managing and maintaining multi-language pre-commit hooks. ... Git hook scripts are useful for identifying simple issues before submission to ...
Read more >
Gitlint - Joris Roovers
Commit message hook: Auto-trigger validations against new commit message right when you're committing. Also works with pre-commit. Easily integrated: Gitlint is ...
Read more >
How to use git pre-commit hooks, the hard way and the easy ...
Git hooks in general, are scripts that get run when a specific event occurs in git. They can be written in any language...
Read more >
language-formatters-pre-commit-hooks - Python package - Snyk
Learn more about language-formatters-pre-commit-hooks: package health score, popularity, security, maintenance, versions and more.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found