So in my pre-commit I want to run python requests to test whether certain urls are valid before committing.
The problem I am having is the requests library is not installed.
Error
- hook id: pre-commit-py
- exit code: 1
Traceback (most recent call last):
File "hooks/pre-commit.py", line 8, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I have tried setting up a virtual env with pipenv shell and installing requests there, but it doesn't seem to be relevant to the pre-commit environment.
I also tried using a different repo in .pre-commit-config.yaml
repos:
- repo: https://github.com/psf/requests.git
hooks:
- id: pre-commit-py
name: pre-commit-py
entry: python hooks/pre-commit.py
language: python
pass_filenames: false
Code to reproduce
hooks/pre-commit.py
import os
import sys
import requests
try:
get = requests.get(url, timeout=5)
if get.status_code == 200:
print('good')
except Exception as e:
sys.exit(1)
.pre-commit-config.yaml
repos:
- repo: local
# - repo: https://github.com/psf/requests.git
hooks:
- id: pre-commit-py
name: pre-commit-py
entry: python hooks/pre-commit.py
language: python
pass_filenames: false