Skip to content

Fix platform-specific default virtualenvs path for Poetry on Windows and macOS#1213

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-poetry-virtualenvs-path
Closed

Fix platform-specific default virtualenvs path for Poetry on Windows and macOS#1213
Copilot wants to merge 3 commits intomainfrom
copilot/fix-poetry-virtualenvs-path

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 8, 2026

  • Extract a getDefaultPoetryVirtualenvsPath() helper function in poetryUtils.ts that returns the platform-specific default path for Poetry virtualenvs
  • Replace all 3 hardcoded Linux paths with the new helper
  • Add unit tests for the new getDefaultPoetryVirtualenvsPath() function (7 tests, all passing)
  • Revert unrelated package-lock.json changes
  • Add test for getUserHomeDir() returning undefined
  • Run full test suite (587 passing, 4 pending - all pre-existing)
  • Run code review and CodeQL checks
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
Copy link
Copy Markdown
Member

@karthiknadig karthiknadig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fix is correct and well-implemented. The new getDefaultPoetryVirtualenvsPath() function properly handles platform-specific paths for Windows, macOS, and Linux.

Note: The PR includes unrelated package-lock.json changes (adding "peer": true to many packages). Consider reverting those before merging.

cc @copilot

const result = getDefaultPoetryVirtualenvsPath();

assert.strictEqual(result, undefined);
});
Copy link
Copy Markdown
Member

@karthiknadig karthiknadig Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also testing when getUserHomeDir() returns undefined (not just empty string ''), since that's also a possible return value from that function.

@copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for getUserHomeDir() returning undefined in 7b16f74.

@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Feb 10, 2026
@karthiknadig
Copy link
Copy Markdown
Member

@copilot please address review comments

Co-authored-by: karthiknadig <3840081+karthiknadig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 10, 2026

The core fix is correct and well-implemented. The new getDefaultPoetryVirtualenvsPath() function properly handles platform-specific paths for Windows, macOS, and Linux.

Note: The PR includes ...

Reverted the unrelated package-lock.json changes in 7b16f74.

Copilot AI requested a review from karthiknadig February 10, 2026 23:03
Copilot stopped work on behalf of karthiknadig due to an error February 10, 2026 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poetry: Incorrect default virtualenvs path on Windows and macOS

2 participants