matangover/mypy-vscode

Support to use subdirectory as root directory for mypy

aleksanb opened this issue · 7 comments

Hello.

Great work on developing this plugin, it really just works <3.
I have a question: our project has a structure like

backend
>app
>>hyre
>>>actual.py
>>>python.py
>>>files.py
>>mypy.ini
>othersubdirectories

I'd like to be able to open the root directory, backend in vscode to be able to see all files in the repo, but because we use a plugin to mypy, django-mypy, that uses the following key in mypy.ini to specify the location of django settings, we have to use app as the root dir in vscode instead.

bilde

This is because if myproject is the vscode root, then the imports of hyre.settings fails, as no module named hyre is (rightly) accessible from the root.

So my suggestion for a solution would be:
Could we add a setting key to specify what folder to run dmypy from?

Hi, thanks for your suggestion! What happens if you set django_settings_module = backend.hyre.settings?

Could we add a setting key to specify what folder to run dmypy from?

In general I don't have anything against adding such an option, so if you feel like making a PR I'll be happy to accept it

Hi, thanks for your suggestion! What happens if you set django_settings_module = backend.hyre.settings?

This might work. I'll test it. The weirdest thing then is that the .ini file has to know about the folder structure it's contained in further out

Right, because the thing is that it's not really the ini file that has to know about it, it's the "mypy django" plugin, which is imported by mypy, which tries to import your settings module. (I'm just guessing... because I've never used this plugin)

Yeah, that seems correct.

There is a concept of PYTHONPATH="app" that's already used by VSCode, perhaps respecting that variable would solve things.

Mypy has the mypy_path config option for adding directories to the module search path. This setting seems by the way to also be respected by the mypy_django plugin. Does this solve your issue?