Skip to content

poetry env list and other commands do not handle case-insensitive paths as cwd on Windows #3829

@karrtikr

Description

@karrtikr
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

Hi VSCode Python extension dev here 👋 We're planning to support Poetry envs in the extension (microsoft/vscode-python#8372 (comment)).

In order to discover environments, we planned to run poetry env list command. The command works fine in terminal when cwd is in case-exact state.

image

But when drive begins with a lowercase c: instead (which is also a valid path on Windows), things don't seem to work. Every other command other than poetry env list works fine. This can be seen when executed via nodejs.child_process API, it returns empty stdout.

import { exec } from 'child_process';

function shellExecute(command: string, options: ShellOptions = {}): Promise<ExecutionResult<string>> {
    return new Promise((resolve, reject) => {
        const callback = (e: any, stdout: any, stderr: any) => {
            if (e && e !== null) {
                reject(e);
            } else {
                resolve({ stderr: stderr && stderr.length > 0 ? stderr : undefined, stdout });
            }
        };
        exec(command, options, callback); 
    });
}

const result1 = await shellExec('poetry env list', {
    cwd: 'C:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\poetry@2-tutorial-project',
});
console.log('poetry env list', result1.stdout);
// Prints:
// poetry env list poetry_2-tutorial-project-6hnqYwvD-py3.7
// poetry_2-tutorial-project-6hnqYwvD-py3.8
// poetry_2-tutorial-project-6hnqYwvD-py3.9

const result2 = await shellExec('poetry env info -p', {
    cwd: 'C:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\poetry@2-tutorial-project',
});
console.log('poetry env info', result2.stdout);
// Prints:
// poetry env info C:\Users\karraj\OneDrive - Microsoft\Desktop\folders\poetry@2-tutorial-project\.venv

// Now the drive letter begins with `c:` instead of `C:`.
const result3 = await shellExec('poetry env list', {
    cwd: 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\poetry@2-tutorial-project',
});
console.log('poetry env list', result3.stdout);
// Prints:
// poetry env list

const result4 = await shellExec('poetry env info -p', {
    cwd: 'c:\\Users\\karraj\\OneDrive - Microsoft\\Desktop\\folders\\poetry@2-tutorial-project',
});
console.log('poetry env info', result4.stdout);
// Prints:
// poetry env info c:\Users\karraj\OneDrive - Microsoft\Desktop\folders\poetry@2-tutorial-project\.venv
// ^Interesting: drive letter begins with `c:` in the output as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions