Questions tagged [pre-commit.com]

For questions regarding the pre-commit framework, not to be confused with git pre-commit hooks generally. Use this tag only when your question involves the framework. The tool pre-commit is a framework for managing and maintaining multi-language pre-commit hooks.

309 questions
6
votes
1 answer

How to propertly configure my pre-commit and pre-push hooks?

I have a simple python project with a single file currently. It exists within the static/cgi-bin folder of my project. Currently, in the base of my directory, I have a .pre-commit-config.yaml file, and I have not touched the files in the .git/hooks…
niketp
  • 409
  • 1
  • 9
  • 20
5
votes
1 answer

Run mypy from pre-commit for different directories

I have the following structure for my project: project/ ├── backend │   ├── api_v1 │   ├── api_v2 │   └── api_v3 └── frontend Each of the API dirs, api_v1, api_v2, and api_v3, have python files. I would like to run pre-commit for each of these…
npk
  • 1,512
  • 1
  • 13
  • 26
5
votes
2 answers

Uninstalled pre-commit preventing 'git commit' (pipenv)

I recently uninstalled pre-commit from my environment. I performed the following in pipenv: pipenv --rm pipenv install -r requirements.txt I ensured that the pre-commit module was no longer in the…
pymat
  • 1,090
  • 1
  • 23
  • 45
5
votes
1 answer

pre-commit not using virtual environment

I added this to pre-commit-config.yml - repo: local hooks: - id: python-hook name: python-hook entry: python python_script.py language: python pass_filenames: false Where python_script.py has the…
caverac
  • 1,505
  • 2
  • 12
  • 17
5
votes
1 answer

Use pre-commit hook for black with multiple language versions for python

We are using pre-commit to format our Python code using black with the following configuration in .pre-commit-config.yaml: repos: - repo: https://github.com/ambv/black rev: 20.8b1 hooks: - id: black language_version:…
Cord Kaldemeyer
  • 6,405
  • 8
  • 51
  • 81
5
votes
4 answers

How specify pre-commit --from-ref for Gitlab?

I want to check by pre-commit files that was changed in git branch in Gitlab CI. What arg for --from-ref I need to use? pre-commit run --from-ref=? --to-ref=HEAD Example from pre-commit documentation raises error. $ pre-commit run…
voronin
  • 659
  • 6
  • 8
5
votes
1 answer

Why does mypy raise error when I run it with pre-commit for django-reset-framework?

I'm trying to automate my tests and code static analysis with pre-commit.My .pre-commit-config.yaml is like below: # . # . # . - repo: https://github.com/pre-commit/mirrors-mypy rev: 'v0.910' hooks: - id: mypy args:…
5
votes
1 answer

Pre-commit not finding python packages

Im using pyenv to support having different versions of python. In a project using python 3.7 I also want linting with pre-commit to run when doing code changes. But when the lint rules run, pre-commit seem to be looking in a cache folder under the…
Tomas B
  • 121
  • 2
  • 6
5
votes
1 answer

Can the python pre-commit tool consider a subdirectory as a base of the project?

I have a repo like this: myrepo/ .git tool1/ src/main.py tests/test.py .pre-commit-config.yaml Where the config is: repos: - repo: local hooks: - id: pytest-cov name: pytest coverage …
inger
  • 19,574
  • 9
  • 49
  • 54
5
votes
3 answers

Prettier using pre-commit(.com) does not re-stage changes

I started using Prettier + eslint using pretty-quick & husky (option 2). It behaves as-expected, i.e., reformats code during a commit (or amend) and includes the changes in the commit. My monorepo needed (several) more pre-commit hooks, so I ended…
Zane Claes
  • 14,732
  • 15
  • 74
  • 131
5
votes
1 answer

pre-commit run unittest git hooks: ModuleNotFoundError for installed python module in environment

I use pre-commit to handle git hooks for my git project. When I use it, the pre-commit run -a command keeps to skip the test execution: (smartexchange) trnbook:smartexchange ale$ pre-commit run unittest…
4
votes
1 answer

pre-commit is failing with "Missing required key: rev"

I've been using the pre-commit tool for years! and it's worked great until recently when it started failing with a mysterious error message: $ pre-commit run flake8 --all-files An error has occurred: InvalidConfigError: ==> File…
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
4
votes
0 answers

Pre-commit fixes a file correctly using the cli, but changes it back when I attempt to commit the file

I am trying to use isort to automatically fix import orders. When I run pre-commit run --files=myfile.py it correctly updates my imports (by adding a line between known third party imports and internal package imports). However, when I try to commit…
cammil
  • 9,499
  • 15
  • 55
  • 89
4
votes
0 answers

How to get .env to pre-commit + mypy + django-stubs

I try to configurate start mypy + django-stubs cheking before commiting. I use pre-commit for it. When I try to commit, I have error django.core.exceptions.ImproperlyConfigured: Set the POSTGRES_DB environment variable. This variable is in .env…
4
votes
1 answer

pre-commit authenticating to gitlab

I'm new to SQLFluff and am interested in a pre-commit check of changed files for rule violations. SQLFluff is working correctly, and to get it working with pre-commit I'm following the guide found here, but am confused by pre-commit asking for git…
Josh Olsen
  • 49
  • 3