A framework for managing and maintaining multi-language pre-commit hooks.

であるほうの pre-commit は、openssl の dll が必要であるが、Windows で anaconda 環境の Python は適切な設定がされていない (しらんけど)。 したがって、anaconda 環境の Python から pre-commit を呼び出すと、初回に以下のようなエラーが現れる。

git commit -m 'm'
[INFO] Installing environment for https://github.com/pycqa/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('C:\\Users\\user\\.cache\\pre-commit\\repo8bqj2zi0\\py_env-python3.9\\Scripts\\python.EXE', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing c:\users\user\.cache\pre-commit\repo8bqj2zi0
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Could not fetch URL https://pypi.org/simple/mccabe/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/mccabe/ (Caused by SSLError("Can't connec
t to HTTPS URL because the SSL module is not available.")) - skipping

stderr:
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mccabe/
    WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mccabe/
    WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mccabe/
    WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mccabe/
    WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/mccabe/
    ERROR: Could not find a version that satisfies the requirement mccabe<0.8.0,>=0.7.0 (from flake8) (from versions: none)
    ERROR: No matching distribution found for mccabe<0.8.0,>=0.7.0

Check the log at C:\Users\user\.cache\pre-commit\pre-commit.log

システムにインストールされた Python は適切な設定がされているので (しらんけど)、pre-commit がシステムにインストールされた Python を使うように -m を使って pre-commit のインストールをする必要がある。

%HOMEPATH%\AppData\Local\Programs\Python\Python38\python.exe -m pip install pre-commit
%HOMEPATH%\AppData\Local\Programs\Python\Python38\python.exe -mpre_commit uninstall
%HOMEPATH%\AppData\Local\Programs\Python\Python38\python.exe -mpre_commit install

ここまでするととりあえず pre-commit が使えるようになる。

参考