Open LanDinh opened 4 years ago
You can get around this by using PYTHONPATH=/path/to/src mypy .
. That way you're still running mypy from the project directory, but since your source directory is added to PYTHONPATH
each app can be imported. Another possibility is using bash -c "cd /path/to/src && mypy ."
, which lets you run mypy in the source directory. Unfortunately the latter breaks the functionality where you can click on errors in the plugin panel to navigate to the correct place in the code, presumably because the paths are expected to be relative to the project root. Even forcing the paths to be absolute with --show-absolute-path
doesn't fix this.
I ended up writing a bash script which I can run using run configurations, but thanks anyways!
Mypy seems to have problems with Django projects containing multiple apps, not being able to follow imports to the other apps when running from the root directory. I've already filed a ticket with mypy itself about this, but there's no answer there yet.
A workaround I've found using the console that when I cd into the main source folder instead of the project root and list all apps manually, the imports work as expected. However, that's not possible with the mypy plugin, and I hate having to switch out of my IDE just for running mypy when a plugin already exists - adding the option to choose where to run mypy from should be easy to configure. I've already tried appending
cd <foldername>;
to the mypy command, but that doesn't work (error:The system cannot find the path specified.
). It works just fine if the command field only contains thecd
command, without mypy, but combining both doesn't work.The reason why the project root is not the source root in my case is that I have a multilanguage project (Python / Django for the backend, Typescript / ReactJS for the frontend).