Skip to content

Pipenv: Missing support for WORKON_HOME and XDG_DATA_HOME environment variables #1185

@karthiknadig

Description

@karthiknadig

Problem

The Pipenv implementation doesn't check the WORKON_HOME and XDG_DATA_HOME environment variables when locating centralized virtual environments.

Background

Pipenv can store virtualenvs in multiple locations:

  1. WORKON_HOME (if set) - commonly shared with virtualenvwrapper
  2. XDG_DATA_HOME/virtualenvs (Linux, if XDG_DATA_HOME is set)
  3. ~/.local/share/virtualenvs (Linux/macOS default)
  4. ~/.virtualenvs (alternative location)

Current State

The extension relies entirely on PET server for discovery and doesn't explicitly support these environment variables in its own logic.

PET Server Reference

The PET server properly checks these in pet-pipenv/src/lib.rs:

fn get_pipenv_virtualenv_dirs(env_vars: &EnvVariables) -> Vec<PathBuf> {
    let mut dirs: Vec<PathBuf> = vec![];

    // WORKON_HOME can be used by pipenv as well
    if let Some(workon_home) = &env_vars.workon_home {
        if workon_home.exists() {
            dirs.push(norm_case(workon_home));
        }
    }

    // XDG_DATA_HOME/virtualenvs (common on Linux)
    if let Some(xdg_data_home) = &env_vars.xdg_data_home {
        let xdg_venvs = PathBuf::from(xdg_data_home).join("virtualenvs");
        if xdg_venvs.exists() {
            dirs.push(norm_case(xdg_venvs));
        }
    }
    // ...
}

Suggested Fix

If the extension needs to perform any local discovery or validation, it should honor these environment variables:

function getPipenvVirtualenvDirs(): string[] {
    const dirs: string[] = [];
    
    // WORKON_HOME
    const workonHome = process.env.WORKON_HOME;
    if (workonHome && fs.existsSync(workonHome)) {
        dirs.push(workonHome);
    }
    
    // XDG_DATA_HOME/virtualenvs
    const xdgDataHome = process.env.XDG_DATA_HOME;
    if (xdgDataHome) {
        const xdgVenvs = path.join(xdgDataHome, 'virtualenvs');
        if (fs.existsSync(xdgVenvs)) {
            dirs.push(xdgVenvs);
        }
    }
    
    // Default locations...
    return dirs;
}

Impact

Users with custom WORKON_HOME or XDG_DATA_HOME configurations may have pipenv environments that aren't discovered or correctly associated with projects.

Affected File

src/managers/pipenv/pipenvUtils.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