Open tamird opened 10 months ago
For a setup like this:
- monorepo
- libA
- pyproject.toml
- subDirA
- myfile.py
- libB
- pyproject.toml
We recommend using code-workspace
file. When you open a monorepo, there is no way for us to say which folders are really the workspaces. Using code-workspace
file defines which folders to treat as workspaces. So for your project a code-workspace file will look like this:
project.code-workspace
:
{
"folders": [
{
"path": "libA"
},
{
"path": "libB"
}
],
"settings": {
// put your general settings here
}
}
This will run mypy
with libA
and libB
as cwd automatically and ${workspaceFolder}
will resolve to the correct workspace folder, depending on the file. Each of those can have their own virtual environments. You will have to ensure they are selected correctly by running Python: Select Environment
. Once it is setup correctly we will use the selected virtual environment depending on the file you are trying to lint.
About https://code.visualstudio.com/docs/editor/variables-reference , if you see the details those are only supported in launch.json
and task.json
and not settings.json
. they are not supported in settings.json
because the context needed to determine some of those things may not be available when in that mode. We added support to some of them that we felt we could calculate.
This is largely the setup I tried, but it doesn't work properly with interpreter selection (and has a number of other issues, see https://github.com/microsoft/vscode-python/issues/21204#issuecomment-1890903624).
I think this issue is probably infeasible, feel free to close, but the situation with python monorepos remains not great.
One thing we can do that is typically done by tools themselves is a way to search parents until pyproject.toml
or mypy.ini
(one of the setting files) is found. something like ${settingDir}
. May need a better name for this.
I will tur this into a feature request. If this gets solved with generic mono-repo support then great. Otherwise we can explore this solution.
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.
Would be great to have proper monorepository support without code-workspace (because they don't work with devcontainers). In my setup (Poetry with in-project .venv, MyPy, monorepository with linked packages in GitHub Codespaces), this extension is currently not usable.
This feels related to an issue I raised earlier: https://github.com/microsoft/vscode-mypy/issues/234
Would be great to support some kind of "current project" scope for type checking!
The instructions added in https://github.com/microsoft/vscode-mypy/commit/aee38320a767a728b2ff9dd7383cd100c0516e3e don't work in the presence of additional directories. Consider:
when running on
myfile.py
I want thecwd
to belibA
, notsubDirA
. I think the correct value should be${fileWorkspaceFolder}
but this produces a crash before and after this patch.It would also be good to log something better when this crash happens. Right now you just get
This is a common thing when using multiple virtual environments as suggested in https://github.com/microsoft/vscode-python/wiki/Mono-Repo-Set%E2%80%90up-Guide#scenario-2-separate-virtual-environments. I think what we want is
${fileWorkspaceFolder}
or${workspaceFolder}
-- I'm not sure because the docs are confusing. But we want the workspace folder to which the currently open file belongs.https://code.visualstudio.com/docs/editor/variables-reference