3

I am using a python package called pre-commit to standardize the git workflow for my team.

I am having some issues setting up a pre-commit hooks with this package https://github.com/pre-commit/mirrors-mypy due to company proxy with github.

I decided to download the package and upload it to our local bitbuket server and setup pre commit for it to use as a local repo.

Here's my .pre-commit-config.yaml file

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
-   repo: http://localserver/scm/~username/local_mypy.git
    rev: '03f936cbf67'
    hooks:
    -   id: mypy

I then ran pre-commit install and in the my git bash I did

git commit -a -m"let's see if pre-commit works"

But the result I get is

[INFO] Installing environment for http://localserver/scm/~username/local_mypy.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('H:\\.cache\\pre-commit\\repo3yl4ty_p\\py_env-python3.6\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing h:\.cache\pre-commit\repo3yl4ty_p
    Could not fetch URL https://pypi.org/simple/mypy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/mypy/ (Caused by SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)) - skipping

stderr:
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)': /simple/mypy/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)': /simple/mypy/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)': /simple/mypy/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)': /simple/mypy/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:833)'),)': /simple/mypy/
    ERROR: Could not find a version that satisfies the requirement mypy==0.800 (from pre-commit-dummy-package)
    ERROR: No matching distribution found for mypy==0.800

Check the log at H:\.cache\pre-commit\pre-commit.log
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
mike_gundy123
  • 469
  • 5
  • 18
  • 1
    the error here looks like your proxy is interfering with `pip install` -- what happens if you make a virtualenv and run `pip install mypy`, does it error in the same way? if so then it's not an issue with pre-commit - the pre-commit author – anthony sottile Feb 05 '21 at 17:02
  • okay that makes sense, guess I was confused on how to use pre-commits with a local repo. How would I go about setting it up this mypy with pre-commits without having to deal with the pip install when running the pre-commit? (Hope that made sense) – mike_gundy123 Feb 05 '21 at 21:07
  • 1
    you'd probably use a [`language: system`](https://pre-commit.com/#system) hook with [`repo: local`](https://pre-commit.com/#repository-local-hooks) but at that point you're losing most of the benefits of the framework – anthony sottile Feb 05 '21 at 22:09
  • oh wow just realized I'm talking to the owner/maintainer of the package! Thank you for your work cause the package seems really cool! I just have some weird edge cases (due to company's network :/) I was looking though some of the issues found on the github like https://github.com/pre-commit/pre-commit/issues/266 and https://github.com/pre-commit/pre-commit/issues/178 – mike_gundy123 Feb 05 '21 at 22:47
  • Maybe I am just being dense, but I am able to get the hook to run when I use pre-commit run, but it doesn't seem to be running all the python files. repos: - repo: http://localserver/scm/~username/local_mypy.git rev: sha hooks: - id: mypy name: mypy language: system files: \.py but it passes the test even though I have it set up for it to fail (I am running windows) – mike_gundy123 Feb 05 '21 at 22:50
  • 1
    `pre-commit run` by default only runs on staged files (simulating what'd happen if you immediately went to commit) -- you can use `pre-commit run --all-files` to run against all of them – anthony sottile Feb 05 '21 at 22:59
  • Oooooooh, okay ya that helped! thank you! next(and hopefully last question) when I am running git commit it says 'Executable '{id}' not found'. Why might it not work in git commit but pre-commit run works fine? – mike_gundy123 Feb 05 '21 at 23:06
  • 1
    might be better to join my discord for further conversation -- it's linked at the bottom here: https://pre-commit.com/#getting-help -- my guess is you don't have whatever virttualenv activated when running `git commit` (but it's difficult to know exactly without seeing more info) – anthony sottile Feb 05 '21 at 23:28
  • @mike_gundy123 How you resolved this? Can you post it as answer? – shaik moeed Feb 14 '23 at 06:04

0 Answers0