Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't configure which folder (d)mypy is run from #56

Open
LanDinh opened this issue Jul 19, 2020 · 2 comments
Open

Can't configure which folder (d)mypy is run from #56

LanDinh opened this issue Jul 19, 2020 · 2 comments

Comments

@LanDinh
Copy link

LanDinh commented Jul 19, 2020

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 the cd 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).

@henribru
Copy link

henribru commented Feb 25, 2021

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.

@LanDinh
Copy link
Author

LanDinh commented Apr 5, 2021

I ended up writing a bash script which I can run using run configurations, but thanks anyways!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants