Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Poetry uses platform-specific cache directories, but the fallback path was hardcoded to the Linux default (~/.cache/pypoetry/virtualenvs) on all platforms, preventing environment discovery on Windows and macOS.

Changes

  • Extract getDefaultPoetryVirtualenvsPath() — returns the correct default path per platform:
    • Linux: ~/.cache/pypoetry/virtualenvs
    • macOS: ~/Library/Caches/pypoetry/virtualenvs
    • Windows: %LOCALAPPDATA%\pypoetry\Cache\virtualenvs (falls back to %APPDATA%)
  • Replace all 3 hardcoded Linux paths in poetryUtils.ts with calls to the new helper
  • Add unit tests covering all platform variants and edge cases
export function getDefaultPoetryVirtualenvsPath(): string | undefined {
    if (isWindows()) {
        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');
        return undefined;
    }
    const home = getUserHomeDir();
    if (!home) return undefined;
    if (process.platform === 'darwin')
        return path.join(home, 'Library', 'Caches', 'pypoetry', 'virtualenvs');
    return path.join(home, '.cache', 'pypoetry', 'virtualenvs');
}

Aligns with the PET server's Rust implementation which uses Platformdirs for the same purpose.

Original prompt

This section details on the original issue you should resolve

<issue_title>Poetry: Incorrect default virtualenvs path on Windows and macOS</issue_title>
<issue_description>## 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</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

On Windows, Poetry stores virtualenvs in %LOCALAPPDATA%\pypoetry\Cache\virtualenvs
(or %APPDATA%\pypoetry\Cache\virtualenvs). On macOS, it uses
~/Library/Caches/pypoetry/virtualenvs. The previous code hardcoded the
Linux path (~/.cache/pypoetry/virtualenvs) for all platforms.

Extract getDefaultPoetryVirtualenvsPath() to return the correct
platform-specific path and use it in all 3 locations that previously
had the hardcoded Linux path.

Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect default virtualenvs path for Poetry on Windows and macOS Fix platform-specific default virtualenvs path for Poetry on Windows and macOS Feb 8, 2026
Copilot AI requested a review from karthiknadig February 8, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poetry: Incorrect default virtualenvs path on Windows and macOS

2 participants