Skip to content

Fall back to the next priority when defaultEnvManager has no environment for a scope #2000

Open

Description

Written with Claude Code (AI-assisted) and reviewed by me.

Request

When python-envs.defaultEnvManager names a manager that has no environment for a given scope, fall through to the next priority (python.defaultInterpreterPath, then auto-discovery) instead of selecting nothing.

That would make a single user-level setting mean "use this manager where it applies, otherwise behave as usual", which is what you want with project-scoped managers like Pixi or Hatch.

Current behaviour

With "python-envs.defaultEnvManager": "renan-r-santos.pixi-code:pixi" in user settings (Windows 11, Python Environments 1.42.0, Pixi Code 0.2.0):

  • The Pixi project folder correctly gets its Pixi environment.
  • The global scope gets nothing, because a Pixi manager has no global environment:
    [interpreterSelection] global: none (source: defaultEnvManager)
    
    Anything outside the workspace folders (the Settings editor, a file from a parent folder, an untitled file) then has no interpreter, and the Python extension shows "An Invalid Python interpreter is selected" even though the workspace's environment is valid.
  • By the same logic, opening any non-Pixi project (e.g. one with a .venv) would select nothing for it as well.

The only way to avoid this today is to set defaultEnvManager per workspace in every Pixi project, which loses the convenience of a user-level default.

Where this happens

In src/features/interpreterSelection.ts, resolvePriorityChainCore returns as soon as the manager named by defaultEnvManager is registered (return { result: { manager, source: 'defaultEnvManager' }, errors }). applyInitialEnvironmentSelection then uses result.manager.get(scope) as the environment, including when it's undefined.

Possible approaches

  1. Fall through in the priority chain: if the manager from pythonProjects[] / defaultEnvManager returns no environment for the scope, continue with priority 3 and then 4, and record the source accordingly. This would be generic and would cover every third-party manager.
  2. Document a contract for managers: isExplicitSelection already describes managers that "have no environment of their own" returning "a fallback owned by another manager", which the built-in venv manager does. If that's the intended design, third-party managers (Pixi, Hatch) could be asked to do the same, and the API docs for EnvironmentManager.get() could say so.

Option 1 seems more robust to me, since each extension would otherwise have to re-implement fallback logic. But I'd like to know which direction you prefer before proposing a PR.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions