How to provide a source directory in the [tool.django-stubs] directive of a pyproject.tom file?

759 Views Asked by At

I'm using a src directory as root source directory in my django projects.

I'm trying to perform pre-commit actions on those django projects, with mypy and django-stubs.

Is is a way to say in pyproject.toml than the source root is in src/ ?

For now, I've:

[tool.django-stubs]
django_version = "3.2"
django_apps = ["account", "seniors", "seniors_app"]
django_settings_module = "seniors.settings.dev"
ignore_missing_settings = true
ignore_missing_model_attributes = true
pre-commit run --all 
...
ModuleNotFoundError: No module named 'seniors'

When I put django_settings_module = "src.seniors.settings.dev", I've some errors later on importing the other modules ( account...)

Have you any ideas ? For sure I don't want to change my project layout !

Thanks !

2

There are 2 best solutions below

0
On

Use the --config-file

cd src
poetry run mypy . --config-file=../pyproject.toml
0
On

using this one helped me https://mypy.readthedocs.io/en/stable/config_file.html#confval-mypy_path

i added to settings [mypy] mypy_path = $MYPY_CONFIG_FILE_DIR/src