Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 !

like image 847
frague Avatar asked Dec 05 '25 02:12

frague


2 Answers

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

like image 161
MrClaudS Avatar answered Dec 08 '25 20:12

MrClaudS


Use the --config-file

  • https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-config-file
cd src
poetry run mypy . --config-file=../pyproject.toml
like image 35
Pando Avatar answered Dec 08 '25 19:12

Pando