Skip to content

type checker project boundaries #948

@kinto0

Description

@kinto0

Hey, thanks for working on this: I'm excited about this extension and how it can help in one of the most confusing parts of setting up a Python project in VSCode. I work on Pyrefly and have a few questions about project boundaries as they relate to workspace folders.

I'm sorry I haven't been able to test/try this myself since I don't see the Python tab on the left from the video (I reloaded my window + opened a python file after switching to the pre-release version). Please let me know if I'm missing something there and should test this all myself and re-ask these questions.

In a normal python project, there might be multiple python roots in a project. For example, I might run python3 script.py from root/scripts and use a conda environment for other code execution. IDE services usually work in root/scripts because of Pyright's fallback heuristic of "pretend every parent directory is a project root". This small example is usually OK enough not to create a new environment for each one.

But in a megarepo, this problem becomes much more difficult: there can be thousands of projects with their own python environment. The general advice is to open each project as a workspace folder in VSCode: this lets you use the preexisting interpreter selector to select environments per-project. But this approach does not scale well and many people forget. So in big megarepos, we've used the VSCode API to automatically open any parent workspace folders that have .vscode/settings.json in order to find the defaultInterpreterPath setting and work automatically (it's frustrating that it doesn't upwards-search for this file). This is not great since people don't like us messing with their VSCode settings.

I'm hoping the environments extension can help in the Megarepo since I think the problem is more common than just at Meta.

From reading the documentation on this (sorry I can't test it successfully), I see pythonProjects which is "A list of Python workspaces, specified by the path, in which you can set particular environment and package managers". I wonder if this setting can help us by dynamically adding these for each project root.

  • How will these interact with workspace folders? Will it always be 1:1?
  • Are there plans for these to be able to find pyproject.tomls that aren't directly at a root workspace folder?

Type checkers like Pyrefly, Ty, Mypy, etc all use a mix of pyproject.tomls, their own configuration, VSCode workspace / environment settings, to understand the "scope" of a project. I wonder if we could allow these extensions to add pythonProjects through some API if they find a configuration file. These checkers (and Pyright does this too) already need upwards-search and create their own combined project scope based on this combined configuration - should they be able to modify the vscode-python-environments project scope?

Thank you!!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions