Skip to content

Commit d4faf97

Browse files
author
Kartik Raj
authored
Cherry pick fixes for release (#18874)
* Ensure `conda info` command isn't run multiple times during startup when large number of conda interpreters are present (#18808) * Wrap file paths containg an ampersand in double quotation marks for running commands in a shell (#18855) * If a conda environment is not returned via the `conda env list` command, resolve it as unknown (#18856) * If a conda environment is not returned via the conda env list command, resolve it as unknown * News entry * Fix unit tests * Do not use conda run when launching a debugger (#18858) * Do not use conda run when launching a debugger * News * Only build VSIX * Revert "Only build VSIX" This reverts commit 0ade929. * Fixes support for python binaries not following the standard names (#18860) * Fixes support for python binaries not following the standard names * news * Remove comment * Do not validate conda binaries using shell by default (#18866) * Do not validate conda binaries using shell * Fix tests * Fix lint * Fix tests * Ensure string prototypes extension extends are unique enough (#18870)
1 parent 7a00635 commit d4faf97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+222
-188
lines changed

news/2 Fixes/18200.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure `conda info` command isn't run multiple times during startup when large number of conda interpreters are present.

news/2 Fixes/18530.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
If a conda environment is not returned via the `conda env list` command, consider it as unknown env type.

news/2 Fixes/18722.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Wrap file paths containg an ampersand in double quotation marks for running commands in a shell.

news/2 Fixes/18835.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes regression with support for python binaries not following the standard names.

news/2 Fixes/18847.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix launch of Python Debugger when using conda environments.

src/client/common/extensions.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ declare interface String {
2020
* Appropriately formats a string so it can be used as an argument for a command in a shell.
2121
* E.g. if an argument contains a space, then it will be enclosed within double quotes.
2222
*/
23-
toCommandArgument(): string;
23+
toCommandArgumentForPythonExt(): string;
2424
/**
2525
* Appropriately formats a a file path so it can be used as an argument for a command in a shell.
2626
* E.g. if an argument contains a space, then it will be enclosed within double quotes.
2727
*/
28-
fileToCommandArgument(): string;
28+
fileToCommandArgumentForPythonExt(): string;
2929
/**
3030
* String.format() implementation.
3131
* Tokens such as {0}, {1} will be replaced with corresponding positional arguments.
@@ -69,22 +69,24 @@ String.prototype.splitLines = function (
6969
* E.g. if an argument contains a space, then it will be enclosed within double quotes.
7070
* @param {String} value.
7171
*/
72-
String.prototype.toCommandArgument = function (this: string): string {
72+
String.prototype.toCommandArgumentForPythonExt = function (this: string): string {
7373
if (!this) {
7474
return this;
7575
}
76-
return this.indexOf(' ') >= 0 && !this.startsWith('"') && !this.endsWith('"') ? `"${this}"` : this.toString();
76+
return (this.indexOf(' ') >= 0 || this.indexOf('&') >= 0) && !this.startsWith('"') && !this.endsWith('"')
77+
? `"${this}"`
78+
: this.toString();
7779
};
7880

7981
/**
8082
* Appropriately formats a a file path so it can be used as an argument for a command in a shell.
8183
* E.g. if an argument contains a space, then it will be enclosed within double quotes.
8284
*/
83-
String.prototype.fileToCommandArgument = function (this: string): string {
85+
String.prototype.fileToCommandArgumentForPythonExt = function (this: string): string {
8486
if (!this) {
8587
return this;
8688
}
87-
return this.toCommandArgument().replace(/\\/g, '/');
89+
return this.toCommandArgumentForPythonExt().replace(/\\/g, '/');
8890
};
8991

9092
/**

src/client/common/installer/condaInstaller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ export class CondaInstaller extends ModuleInstaller {
7171
flags: ModuleInstallFlags = 0,
7272
): Promise<ExecutionInfo> {
7373
const condaService = this.serviceContainer.get<ICondaService>(ICondaService);
74-
const condaFile = await condaService.getCondaFile();
74+
// Installation using `conda.exe` sometimes fails with a HTTP error on Windows:
75+
// https://github.com/conda/conda/issues/11399
76+
// Execute in a shell which uses a `conda.bat` file instead, using which installation works.
77+
const useShell = true;
78+
const condaFile = await condaService.getCondaFile(useShell);
7579

7680
const pythonPath = isResource(resource)
7781
? this.serviceContainer.get<IConfigurationService>(IConfigurationService).getSettings(resource).pythonPath
@@ -100,11 +104,11 @@ export class CondaInstaller extends ModuleInstaller {
100104
if (info && info.name) {
101105
// If we have the name of the conda environment, then use that.
102106
args.push('--name');
103-
args.push(info.name.toCommandArgument());
107+
args.push(info.name.toCommandArgumentForPythonExt());
104108
} else if (info && info.path) {
105109
// Else provide the full path to the environment path.
106110
args.push('--prefix');
107-
args.push(info.path.fileToCommandArgument());
111+
args.push(info.path.fileToCommandArgumentForPythonExt());
108112
}
109113
if (flags & ModuleInstallFlags.updateDependencies) {
110114
args.push('--update-deps');
@@ -117,8 +121,7 @@ export class CondaInstaller extends ModuleInstaller {
117121
return {
118122
args,
119123
execPath: condaFile,
120-
// Execute in a shell as `conda` on windows refers to `conda.bat`, which requires a shell to work.
121-
useShell: true,
124+
useShell,
122125
};
123126
}
124127

src/client/common/installer/moduleInstaller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ export abstract class ModuleInstaller implements IModuleInstaller {
217217
const argv = [command, ...args];
218218
// Concat these together to make a set of quoted strings
219219
const quoted = argv.reduce(
220-
(p, c) => (p ? `${p} ${c.toCommandArgument()}` : `${c.toCommandArgument()}`),
220+
(p, c) =>
221+
p ? `${p} ${c.toCommandArgumentForPythonExt()}` : `${c.toCommandArgumentForPythonExt()}`,
221222
'',
222223
);
223224
await processService.shellExec(quoted);

src/client/common/process/internal/scripts/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function normalizeSelection(): [string[], (out: string) => string] {
9494
// printEnvVariables.py
9595

9696
export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
97-
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgument();
97+
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgumentForPythonExt();
9898
const args = [script];
9999

100100
function parse(out: string): NodeJS.ProcessEnv {
@@ -113,11 +113,11 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
113113
// could be anything.
114114
return [
115115
script,
116-
command.fileToCommandArgument(),
116+
command.fileToCommandArgumentForPythonExt(),
117117
// The shell args must come after the command
118118
// but before the lockfile.
119119
...shellArgs,
120-
lockfile.fileToCommandArgument(),
120+
lockfile.fileToCommandArgumentForPythonExt(),
121121
];
122122
}
123123

src/client/common/process/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ProcessLogger implements IProcessLogger {
2222
return;
2323
}
2424
let command = args
25-
? [fileOrCommand, ...args].map((e) => e.trimQuotes().toCommandArgument()).join(' ')
25+
? [fileOrCommand, ...args].map((e) => e.trimQuotes().toCommandArgumentForPythonExt()).join(' ')
2626
: fileOrCommand;
2727
const info = [`> ${this.getDisplayCommands(command)}`];
2828
if (options && options.cwd) {

0 commit comments

Comments
 (0)