Skip to content

Poetry: Missing support for POETRY_VIRTUALENVS_IN_PROJECT environment variable #1183

@karthiknadig

Description

@karthiknadig

Problem

The extension does not honor the POETRY_VIRTUALENVS_IN_PROJECT environment variable when determining whether a .venv directory in a project should be treated as a Poetry environment.

Expected Behavior

When POETRY_VIRTUALENVS_IN_PROJECT=true (or 1) is set, Poetry creates virtualenvs in the project's .venv directory. The extension should recognize these as Poetry environments.

Current Behavior

The extension doesn't check this environment variable, so .venv directories in Poetry projects may not be correctly identified as Poetry environments.

PET Server Reference

The PET server properly handles this in pet-poetry/src/env_variables.rs:

poetry_virtualenvs_in_project: env
    .get_env_var("POETRY_VIRTUALENVS_IN_PROJECT".to_string())
    .map(|v| v == "1" || v.to_lowercase() == "true"),

And in pet-poetry/src/environment_locations.rs:

fn should_use_local_venv_as_poetry_env(
    global: &Option<Config>,
    local: &Option<Config>,
    env: &EnvVariables,
) -> bool {
    // Given preference to env variable.
    if let Some(poetry_virtualenvs_in_project) = env.poetry_virtualenvs_in_project {
        return poetry_virtualenvs_in_project;
    }
    // ...
}

Suggested Fix

Add support in poetryUtils.ts to:

  1. Check process.env.POETRY_VIRTUALENVS_IN_PROJECT
  2. Consider .venv as a Poetry env when this is set and the parent has pyproject.toml with [tool.poetry]

Related

This is similar to how poetry.toml local config with virtualenvs.in-project = true should work.

Affected File

src/managers/poetry/poetryUtils.ts

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugneeds PR

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions