Skip to content

Use conda run to validate conda interpreters - #18128

Merged
karrtikr merged 6 commits into
microsoft:mainfrom
karrtikr:condarunselect
Dec 8, 2021
Merged

Use conda run to validate conda interpreters#18128
karrtikr merged 6 commits into
microsoft:mainfrom
karrtikr:condarunselect

Conversation

@karrtikr

@karrtikr karrtikr commented Dec 6, 2021

Copy link
Copy Markdown

Closes #17941

@karrtikr
karrtikr force-pushed the condarunselect branch 2 times, most recently from 621d778 to ee27f7f Compare December 7, 2021 14:55

@karrtikr karrtikr left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I expect #17982 to be modified accordingly based on this PR.

// Note: Single quotes maybe converted to double quotes for printing purposes.
let commandList: string[];
if (!args) {
// It's a quoted command.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Command args are no longer guaranteed to be quoted, for eg. conda, -p etc. are not quoted below:

conda run -p "~\OneDrive - Microsoft\Desktop\vscode-python\.venv" --no-capture-output python "~\OneDrive - Microsoft\Desktop\vscode-python\pythonFiles\interpreterInfo.py"

So no longer rely on this logic.


private getDisplayCommands(command: string): string {
if (this.workspaceService.workspaceFolders && this.workspaceService.workspaceFolders.length === 1) {
command = replaceMatchesWithCharacter(command, this.workspaceService.workspaceFolders[0].uri.fsPath, '.');

@karrtikr karrtikr Dec 7, 2021

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Replace workspace folder path with .

}
const home = getUserHomeDir();
if (home) {
command = replaceMatchesWithCharacter(command, home, '~');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Find traces of path to home in command and replace it with ~.


// Concat these together to make a set of quoted strings
const quoted = argv.reduce((p, c) => (p ? `${p} "${c}"` : `"${c}"`), '');
const quoted = argv.reduce((p, c) => (p ? `${p} ${c.toCommandArgument()}` : `${c.toCommandArgument()}`), '');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This ensures flags like -n/-p are not quoted.

@karrtikr
karrtikr marked this pull request as ready for review December 7, 2021 16:08
@karrtikr
karrtikr requested a review from kimadeline December 7, 2021 16:10
@karrtikr karrtikr changed the title Use conda run to validate interpreters Use conda run to validate conda interpreters Dec 7, 2021
Comment thread src/client/pythonEnvironments/common/environmentManagers/conda.ts
}
// Use a bogus version, at least to indicate the fact that a version was returned.
traceWarn(`Unable to parse Version of Conda, ${versionString}`);
return new SemVer('0.0.1');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did you choose to return a valid object with an invalid value, instead of undefined, an error or throwing an exception?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I just moved this method here from condaService.ts. As to why it was previously done, it is stated in the comment above that we want to distinguish it from the case where no version string is found.

I guess it makes sense to assume it's a really old version when the version string isn't parsable, hence 0.0.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

we want to distinguish it from the case where no version string is found.

What do we need this for?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is existing logic from condaService.ts so I don't really know what it was needed for originally 🤷‍♂️

But my guess is, we still want to use conda related commands for activation, even though conda --version returns incorrect/unparsable version string (atleast it returned something). Returning undefined would mean we're not using conda at all.

@kimadeline kimadeline left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Most of it looks fine to me, the only part I don't understand is the need to return a 0.0.1 invalid version, but this can be addressed separately since it's not blocking and there's already a 2nd PR planned anyway.

@karrtikr karrtikr closed this Dec 8, 2021
@karrtikr karrtikr reopened this Dec 8, 2021
@karrtikr
karrtikr merged commit e477965 into microsoft:main Dec 8, 2021
@karrtikr
karrtikr deleted the condarunselect branch December 8, 2021 07:47
wesm pushed a commit to posit-dev/positron that referenced this pull request Mar 28, 2024
…#18128)

* Use conda run to validate conda interpreters

* Add tests

* Add news entry

* Fix tests

* Add comment to clarify

* Use traceError instead of traceWarn
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.

Can't select Anaconda virtual environment Python 3.10 interpreter

2 participants