Skip to content

Poetry: Incorrect default virtualenvs path on Windows and macOS #1182

@karthiknadig

Description

@karthiknadig

Problem

In poetryUtils.ts, the fallback for Poetry's virtualenvs path uses ~/.cache/pypoetry/virtualenvs on all platforms, but Windows has a different default location.

Current Code

// poetryUtils.ts L169-172
const home = getUserHomeDir();
if (home) {
    poetryVirtualenvsPath = path.join(home, '.cache', 'pypoetry', 'virtualenvs');
}

Issue

Poetry uses platform-specific default locations:

  • Linux: ~/.cache/pypoetry/virtualenvs
  • macOS: ~/Library/Caches/pypoetry/virtualenvs
  • Windows: %LOCALAPPDATA%\pypoetry\Cache\virtualenvs or %APPDATA%\pypoetry\Cache\virtualenvs

The current code hardcodes the Linux path for all platforms, causing Poetry environments to not be discovered on Windows.

PET Server Reference

The PET server correctly handles this via Platformdirs in pet-poetry/src/config.rs:

let default_cache_dir = Platformdirs::new(_APP_NAME.into(), false).user_cache_path();

Suggested Fix

Use platform-specific paths:

function getDefaultVirtualenvsPath(): string | undefined {
    const home = getUserHomeDir();
    if (!home) return undefined;
    
    if (isWindows()) {
        // Try LOCALAPPDATA first, then APPDATA
        const localAppData = process.env.LOCALAPPDATA;
        if (localAppData) {
            return path.join(localAppData, 'pypoetry', 'Cache', 'virtualenvs');
        }
        const appData = process.env.APPDATA;
        if (appData) {
            return path.join(appData, 'pypoetry', 'Cache', 'virtualenvs');
        }
    } else if (process.platform === 'darwin') {
        return path.join(home, 'Library', 'Caches', 'pypoetry', 'virtualenvs');
    }
    
    // Linux default
    return path.join(home, '.cache', 'pypoetry', 'virtualenvs');
}

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