Reputation: 176
I've tried to configurate pre-commit + mypy + django-stubs, so I have error when i try to commit.
ModuleNotFoundError: No module named 'environ'
My configs:
.pre-commit-config.yaml
- 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]
setup.cfg
[mypy]
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
It's look like mypy ignore option ignore_missing_imports = True. Does anyone have any ideas?
Full error trace:
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/**/.cache/pre-commit/patch1646008720-58913.
[WARNING] The 'rev' field of repo 'https://github.com/pre-commit/mirrors-mypy' appears to be a mutable reference (moving tag / branch). Mutable references are never updated after first install and are not supported. See https://pre-commit.com/#using-the-latest-version-for-a-repository for more details. Hint: `pre-commit autoupdate` often fixes this.
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
black....................................................................Passed
isort....................................................................Passed
dotenv-linter........................................(no files to check)Skipped
yamllint.................................................................Passed
flake8...................................................................Passed
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
Error constructing plugin instance of NewSemanalDjangoPlugin
Traceback (most recent call last):
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy/__main__.py", line 12, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 96, in main
File "mypy/main.py", line 173, in run_build
File "mypy/build.py", line 180, in build
File "mypy/build.py", line 231, in _build
File "mypy/build.py", line 478, in load_plugins
File "mypy/build.py", line 456, in load_plugins_from_config
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/main.py", line 143, in __init__
self.django_context = DjangoContext(django_settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 95, in __init__
apps, settings = initialize_django(self.django_settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/mypy_django_plugin/django/context.py", line 77, in initialize_django
settings._setup()
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 71, in _setup
self._wrapped = Settings(settings_module)
File "/home/**/.cache/pre-commit/repon7zquz0p/py_env-python3.9/lib/python3.9/site-packages/django/conf/__init__.py", line 179, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/**/project/config/settings/local.py", line 3, in <module>
from .base import * # noqa
File "/home/**/project/config/settings/base.py", line 6, in <module>
import environ
ModuleNotFoundError: No module named 'environ'
Upvotes: 1
Views: 1263