0

To make a long story short due to company policy I have to make a local copy on our bitbucket server of this repo: https://github.com/pre-commit/mirrors-mypy

I have a python project with a .pre-commmit-config.yaml file that looks like this:

repos:
-   repo: http://host/scm/~user/local_pre-commit_mypy.git
    rev: 'hash'
    hooks:
        - id: mypy
          name: mypy
          types: [python]

When I run:

pre-commit run

in my pycharm terminal I get an output that I want that looks like this:

[INFO] Initializing environment for http://host/scm/~user/local_pre-commit_mypy.git.
[INFO] Installing environment for http://host/scm/~user/local_pre-commit_mypy.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

OCR_test.py:14: error: Function is missing a return type annotation
OCR_test.py:14: note: Use "-> None" if function does not return a value
OCR_test.py:30: error: Function is missing a return type annotation
OCR_test.py:30: note: Use "-> None" if function does not return a value
OCR_test.py:50: error: Function is missing a type annotation
OCR_test.py:77: error: Function is missing a type annotation
OCR_test.py:96: error: Function is missing a return type annotation
OCR_test.py:96: note: Use "-> None" if function does not return a value
OCR_test.py:101: error: Function is missing a return type annotation
OCR_test.py:101: note: Use "-> None" if function does not return a value
OCR_test.py:130: error: Call to untyped function "upload_files_to_cloud" in typed context
Found 7 errors in 1 file (checked 1 source file)

Which is exactly what I expect and want

However when I run:

 git commit -a -m"Changed pre commit stuff"

The result looks like this:

[INFO] Initializing environment for http://host/scm/~user/local_pre-commit_mypy.git.
[INFO] Installing environment for http://host/scm/~user/local_pre-commit_mypy.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

Which gives me mostly what I want, but doesn't give me the proper output like what file and line is causing it to fail.

I want the output from gitbash to look like the output from the pycharm terminal Is there something I am doing wrong, or is this normal?

mike_gundy123
  • 469
  • 5
  • 18
  • 1
    I can't reproduce -- what happens when you run `pre-commit run` at the terminal? it should be identical. it's possible mypy is segfaulting or failing in some other way without output which would lead to result you're seeing - the pre-commit creator – anthony sottile Feb 23 '21 at 23:27
  • Sorry if I am being dense, but do you mean run pre-commit run in the git bash terminal? Cause if so it just says: 'bash: pre-commit: command not found" – mike_gundy123 Feb 24 '21 at 14:25
  • So I tried running: git commit -a -m"does pre-commit show up" in the pycharm terminal and I have the same issue as the gitbash terminal, but doing just pre-commit run gives the proper output – mike_gundy123 Feb 24 '21 at 14:39
  • 1
    well you'll obviously need to activate the virtualenv where pre-commit is installed to run `pre-commit run` -- do that in the terminal – anthony sottile Feb 24 '21 at 15:33
  • Okay, so I got that done. When I run `pre-commit run` in the git bash terminal I get the same error. I was doing some other testing, and when I run pre-commit run in the pycharm terminal and the windows cmd I get `mypy....Passed` (which is correct and corresponds to what happens when I run mypy) but in gitbash I get `mypy....Failed` – mike_gundy123 Feb 24 '21 at 15:46
  • 1
    you'll have to debug what's different then! I'd start by trying to figure out whether you've got the same versions of things in different places. – anthony sottile Feb 24 '21 at 16:45
  • Quick question, is it possible to move where .cache/pre-commit gets saved at? – mike_gundy123 Feb 24 '21 at 17:43
  • 1
    [yes](https://pre-commit.com/#managing-ci-caches) – anthony sottile Feb 24 '21 at 18:17
  • Once again, maybe I am being dense, but where exactly do I set that? Can I just set that in the .pre-commit-config.yaml file? – mike_gundy123 Feb 24 '21 at 19:14
  • 1
    no, those are environment variables – anthony sottile Feb 24 '21 at 19:59
  • Thank you, finally got it to work. Seems like the original location of the environment of the git hooks was causing some kind issue. All i had to do was change the location and it worked. Thanks! – mike_gundy123 Feb 24 '21 at 20:22

0 Answers0