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

Monorepo: allow a way to configure cwd based on pyproject.toml or ini file location #259

Open
tamird opened this issue Jan 24, 2024 · 6 comments
Labels
feature-request Request for new features or functionality needs community feedback

Comments

@tamird
Copy link

tamird commented Jan 24, 2024

The instructions added in aee3832 don't work in the presence of additional directories. Consider:

- libA
  - pyproject.toml
  - subDirA
    - myfile.py
- libB
  - pyproject.toml

when running on myfile.py I want the cwd to be libA, not subDirA. 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

2024-01-24 10:04:59.330 [info] Server: Start requested.
2024-01-24 10:04:59.330 [info] [Error - 10:04:59 AM] Mypy Type Checker client: couldn't create connection to server.
2024-01-24 10:04:59.331 [info] Launching server using command python_monorepo/common/.venv/bin/python failed. Error: spawn python_monorepo/common/.venv/bin/python ENOENT
2024-01-24 10:04:59.331 [error] Server: Start failed: Launching server using command python_monorepo/common/.venv/bin/python failed. Error: spawn python_monorepo/common/.venv/bin/python ENOENT

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

@karthiknadig
Copy link
Member

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.

@karthiknadig karthiknadig self-assigned this Jan 24, 2024
@tamird
Copy link
Author

tamird commented Jan 24, 2024

This is largely the setup I tried, but it doesn't work properly with interpreter selection (and has a number of other issues, see microsoft/vscode-python#21204 (comment)).

I think this issue is probably infeasible, feel free to close, but the situation with python monorepos remains not great.

@karthiknadig
Copy link
Member

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.

@karthiknadig karthiknadig changed the title Mono repo instructions using ${fileDirname} doesn't work with nesting Monorepo: allow a way to configure cwd based on pyproject.toml or ini file location Jan 24, 2024
@karthiknadig karthiknadig removed their assignment Jan 24, 2024
@karthiknadig karthiknadig added feature-request Request for new features or functionality needs community feedback and removed triage-needed labels Jan 24, 2024
@karthiknadig
Copy link
Member

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.

@nf-ssc
Copy link

nf-ssc commented Apr 24, 2024

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.

@athyuttamre
Copy link

This feels related to an issue I raised earlier: #234

Would be great to support some kind of "current project" scope for type checking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality needs community feedback
Projects
None yet
Development

No branches or pull requests

4 participants