I'm trying to automate my tests and code static analysis with pre-commit.My .pre-commit-config.yaml
is like below:
# .
# .
# .
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910'
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
exclude: "[a-zA-Z]*/[a-zA-Z]*/(migrations)/(.)*"
additional_dependencies: [
'tokenize-rt,
'djangorestframework-stubs',
'django-stubs',
]
The pyproject.toml
is:
[tool.mypy]
python_version = "3.8"
plugins = ["mypy_django_plugin.main", "mypy_drf_plugin.main"]
[mypy.plugins.django-stubs]
django_settings_module = "api.shop.shop.settings"
When I run the pre-commit run --all-files
I get the following error:
Error constructing plugin instance of NewSemanalDjangoPlugin
Traceback (most recent call last):
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/bin/mypy", line 8, in <module>
sys.exit(console_entry())
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "mypy/main.py", line 87, in main
File "mypy/main.py", line 165, in run_build
File "mypy/build.py", line 179, in build
File "mypy/build.py", line 229, in _build
File "mypy/build.py", line 475, in load_plugins
File "mypy/build.py", line 453, in load_plugins_from_config
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/mypy_django_plugin/main.py", line 104, in __init__
self.django_context = DjangoContext(django_settings_module)
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/mypy_django_plugin/django/context.py", line 88, in __init__
apps, settings = initialize_django(self.django_settings_module)
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/mypy_django_plugin/django/context.py", line 72, in initialize_django
apps.populate(settings.INSTALLED_APPS)
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/alipqb/.cache/pre-commit/repo94ds7xs0/py_env-python3.8/lib/python3.8/site-packages/django/apps/config.py", line 224, in create
import_module(entry)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'rest_framework'
But I have installed both djangoresetframework
and djangorestframework-stubs
in my environment. What is the problem here?