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 following content
#!/usr/bin/env python
import os
print(os.environ["VIRTUAL_ENV"])
import requests
The package requests
is installed inside the active virtual environment, when I run pre-commit I get this output
/path/to/home/.cache/pre-commit/repouecs3sp4/py_env-python3.7
Traceback (most recent call last):
File "python_script.py", line 7, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
The issue here is that the path to the virtual environment is apparently switched to a different one /path/to/home/.cache/pre-commit/repouecs3sp4/py_env-python3.7
.
Is there something I'm missing here? Thanks for your help