I try to configurate start mypy + django-stubs cheking before commiting. I use pre-commit for it. When I try to commit, I have error django.core.exceptions.ImproperlyConfigured: Set the POSTGRES_DB environment variable. This variable is in .env file, I export variables from .env to Django config using django-environ. And of course .env in .gitignore. So, as far as I understand: pre-commit starts with its own virtual environment, and it doesn't know about my .env file.
Above all, do I correct to understand my situation? If I'm right, how to get variables from .env file to pre-commit enviroment?
My .pre-commit-config.yaml (part)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: ''
hooks:
- id: mypy
exclude: "[a-zA-Z]*/(migrations)/(.)*"
args: [--config=setup.cfg,
--no-strict-optional,
--ignore-missing-imports]
additional_dependencies: [django-stubs, django-environ]
my setup.cfg
[mypy]
python_version = 3.9
allow_redefinition = True
check_untyped_defs = True
ignore_missing_imports = True
incremental = True
strict_optional = True
show_traceback = True
warn_no_return = False
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
plugins = mypy_django_plugin.main
show_column_numbers = True
[mypy.plugins.django-stubs]
django_settings_module = config.settings.local
[mypy_django_plugin]
ignore_missing_model_attributes = True
[mypy-*.migrations.*]
# Django migrations should not produce any errors:
ignore_errors = True