Open leinadao opened 2 years ago
might be a better idea if we could specify a way to point each hook to the right python executable within virtual environment using command or direct path
in the case of poetry
- repo: https://github.com/ecugol/pre-commit-hooks-django
rev: v0.4.0
hooks:
- id: check-absent-migrations
python: 'poetry run python'
in the case of a custom python binary path
- repo: https://github.com/ecugol/pre-commit-hooks-django
rev: v0.4.0
hooks:
- id: check-absent-migrations
python: '/usr/<your-custom-python-path>/bin/python3'
and of course, we can default python executable path to the one presented in the system executable path
I use poetry and have the following dependencies:
The entrypoint commands in check-unapplied-migrations and check-absent-migrations simply run 'python' which fails importing django and / or (depending on the system python packages installed) django-bootstrap-v5. These are required via manage.py and e.g. Django's INSTALLED_APPS.
Manually activating the virtual environment (e.g. poetry shell) before commiting is one solution.
Based on some progress, I believe it would be possible to resolve by adding every dependency to the hook's additional_dependencies, but this is horribly repetative and error-prone.
Instead I've temporarily resolved the issue by overriding the hook's entrypoint to use poetry and so invoke the virtual environment and have access to all dependencies required to run the project's migration code.
Perhaps configuration could be added for which 'python' command to run? And / or cases like this could be added to the documentation.