matangover / mypy-vscode

VS Code extension that provides type checking and analysis for Python code using mypy.
https://marketplace.visualstudio.com/items?itemName=matangover.mypy
Other
93 stars 16 forks source link

Use a specific working directory to run `dmypy` in #89

Open utybo opened 5 months ago

utybo commented 5 months ago

I'm working on a monorepo where all Python files, including the mypy.ini, are in a specific subfolder (e.g. mypythonstuff).

While I can use mypy.targets and mypy.configFile options to select the subfolder in question, I don't think it's working: it seems that the mypy.ini's package-specific settings are completely ignored (maybe because mypy considers the full path to these packages to be mypythonstuff.foo.bar instead of foo.bar 🤔 )

An easy workaround would be to just open the mypythonstuff folder in a separate VS Code window, or as a workspace folder, but that is somewhat more annoying than just being able to set dmypy's current working directory.

(this is similar to #82, but for a single folder)

matangover commented 5 months ago

Thanks for the report. I could definitely add an option for the working directory. Can you give me minimal instructions how to reproduce your issue with mypy.ini not working properly?

utybo commented 5 months ago

Sure! I've made a repro repository here. Instructions are in the README, let me know if you need something else 😄

matangover commented 3 months ago

Thanks for making the nice reproduction repo! and sorry for the delay... I tested your repo. You're right with your interpretation. The exclude rules in mypy.ini are being interpreted relative to mypy's cwd, and not relative to the location of mypy.ini. Thus, the solution for your special use-case is like you requested, to set the working directory. This is not a difficult feature to add.

evbo commented 1 month ago

what about letting mypy look in any subdirectory?:

"mypy-type-checker.cwd": "${workspaceFolder}/*", "mypy-type-checker.reportingScope": "workspace", "mypy-type-checker.preferDaemon": true

matangover commented 1 month ago

@evbo, your comment doesn't seem related to this repo. It is related to Microsoft's mypy extension.

evbo commented 1 month ago

oh sorry, well it works too though :)