Skip to content

Commit c41a92e

Browse files
committed
Ensure isolate script is passed as command arg when installing modules
1 parent ebfc9e7 commit c41a92e

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

news/2 Fixes/11399.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure isolate script is passed as command argument when installing modules.

src/client/common/installer/moduleInstaller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export abstract class ModuleInstaller implements IModuleInstaller {
4545
? await interpreterService.getActiveInterpreter(resource)
4646
: resource;
4747
const pythonPath = isResource(resource) ? settings.pythonPath : resource.path;
48-
const args = internalPython.execModule(executionInfo.moduleName, executionInfoArgs);
48+
const args = internalPython.execModule(executionInfo.moduleName, executionInfoArgs, true, true);
4949
if (!interpreter || interpreter.type !== InterpreterType.Unknown) {
5050
await terminalService.sendCommand(pythonPath, args, token);
5151
} else if (settings.globalModuleInstallation) {

src/client/common/process/internal/python.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import '../../extensions';
45
import { _ISOLATED as ISOLATED } from './scripts';
56

67
// "python" contains functions corresponding to the various ways that
@@ -25,10 +26,15 @@ export function execCode(code: string, isolated = true): string[] {
2526
return args;
2627
}
2728

28-
export function execModule(name: string, moduleArgs: string[], isolated = true): string[] {
29+
export function execModule(
30+
name: string,
31+
moduleArgs: string[],
32+
isolated = true,
33+
useAsCommandArgument = false
34+
): string[] {
2935
const args = ['-m', name, ...moduleArgs];
3036
if (isolated) {
31-
args[0] = ISOLATED; // replace
37+
args[0] = useAsCommandArgument ? ISOLATED.fileToCommandArgument() : ISOLATED; // replace
3238
}
3339
// "code" isn't specific enough to know how to parse it,
3440
// so we only return the args.

src/client/interpreter/locators/services/currentPathService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export class CurrentPathService extends CacheableLocatorService {
9393
private async getInterpreter(options: { command: string; args?: string[] }) {
9494
try {
9595
const processService = await this.processServiceFactory.create();
96-
const pyArgs = Array.isArray(options.args) ? options.args : [];
9796
const [args, parse] = internalPython.getExecutable();
97+
const pyArgs = Array.isArray(options.args) ? options.args.concat(args) : args;
9898
return processService
99-
.exec(options.command, pyArgs.concat(args), {})
99+
.exec(options.command, pyArgs, {})
100100
.then((output) => parse(output.stdout))
101101
.then(async (value) => {
102102
if (value.length > 0 && (await this.fs.fileExists(value))) {

src/test/common/installer/moduleInstaller.unit.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from 'vscode';
2323
import { IApplicationShell, IWorkspaceService } from '../../../client/common/application/types';
2424
import { STANDARD_OUTPUT_CHANNEL } from '../../../client/common/constants';
25+
import '../../../client/common/extensions';
2526
import { CondaInstaller } from '../../../client/common/installer/condaInstaller';
2627
import { ModuleInstaller } from '../../../client/common/installer/moduleInstaller';
2728
import { PipEnvInstaller, pipenvName } from '../../../client/common/installer/pipEnvInstaller';
@@ -51,13 +52,15 @@ import {
5152
import { IServiceContainer } from '../../../client/ioc/types';
5253
import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../constants';
5354

54-
const isolated = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'pythonFiles', 'pyvsc-run-isolated.py');
55+
const isolated = path
56+
.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'pythonFiles', 'pyvsc-run-isolated.py')
57+
.fileToCommandArgument();
5558

5659
/* Complex test to ensure we cover all combinations:
5760
We could have written separate tests for each installer, but we'd be replicate code.
58-
Both approachs have their benefits.
61+
Both approaches have their benefits.
5962
60-
Comnbinations of:
63+
Combinations of:
6164
1. With and without a workspace.
6265
2. Http Proxy configuration.
6366
3. All products.
@@ -464,7 +467,7 @@ suite('Module Installer', () => {
464467
interpreterService.verifyAll();
465468
terminalService.verifyAll();
466469
});
467-
test(`If 'python.globalModuleInstallation' is not set to true, concanate arguments with '--user' flag and send command to terminal`, async () => {
470+
test(`If 'python.globalModuleInstallation' is not set to true, concatenate arguments with '--user' flag and send command to terminal`, async () => {
468471
const info = TypeMoq.Mock.ofType<PythonInterpreter>();
469472
info.setup((t: any) => t.then).returns(() => undefined);
470473
info.setup((t) => t.type).returns(() => InterpreterType.Unknown);

src/test/common/moduleInstaller.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { ConfigurationService } from '../../client/common/configuration/service'
3737
import { CryptoUtils } from '../../client/common/crypto';
3838
import { EditorUtils } from '../../client/common/editor';
3939
import { ExperimentsManager } from '../../client/common/experiments';
40+
import '../../client/common/extensions';
4041
import { FeatureDeprecationManager } from '../../client/common/featureDeprecationManager';
4142
import {
4243
ExtensionInsidersDailyChannelRule,
@@ -143,7 +144,9 @@ import { closeActiveWindows, initializeTest } from './../initialize';
143144

144145
chai_use(chaiAsPromised);
145146

146-
const isolated = path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'pythonFiles', 'pyvsc-run-isolated.py');
147+
const isolated = path
148+
.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'pythonFiles', 'pyvsc-run-isolated.py')
149+
.fileToCommandArgument();
147150

148151
const info: PythonInterpreter = {
149152
architecture: Architecture.Unknown,

0 commit comments

Comments
 (0)