Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/16274.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove execution isolation script.
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1863,12 +1863,6 @@
"description": "Enable auto run test discovery when saving a test file.",
"scope": "resource"
},
"python.useIsolation": {
"type": "boolean",
"default": true,
"description": "Execute tools in isolation from the workspace.",
"scope": "machine"
},
"python.venvFolders": {
"type": "array",
"default": [],
Expand Down
32 changes: 0 additions & 32 deletions pythonFiles/pyvsc-run-isolated.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ export class PythonSettings implements IPythonSettings {

public logging: ILoggingSettings = { level: LogLevel.Error };

public useIsolation = true;

protected readonly changed = new EventEmitter<void>();

private workspaceRoot: Resource;
Expand Down Expand Up @@ -284,8 +282,6 @@ export class PythonSettings implements IPythonSettings {
pythonSettings.get<boolean>('autoUpdateLanguageServer', true),
)!;

this.useIsolation = systemVariables.resolveAny(pythonSettings.get<boolean>('useIsolation', true))!;

// Get as a string and verify; don't just accept.
let userLS = pythonSettings.get<string>('languageServer');
userLS = systemVariables.resolveAny(userLS);
Expand Down
26 changes: 8 additions & 18 deletions src/client/common/process/internal/python.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { _ISOLATED as ISOLATED, getUseIsolationSetting, maybeIsolated } from './scripts';

// "python" contains functions corresponding to the various ways that
// the extension invokes a Python executable internally. Each function
// takes arguments relevant to the specific use case. However, each
Expand All @@ -15,28 +13,21 @@ import { _ISOLATED as ISOLATED, getUseIsolationSetting, maybeIsolated } from './
// into the corresponding object or objects. "parse()" takes a single
// string as the stdout text and returns the relevant data.

export function execCode(code: string, isolated = true): string[] {
export function execCode(code: string): string[] {
let args = ['-c', code];
if (isolated) {
args = maybeIsolated(args);
}
// "code" isn't specific enough to know how to parse it,
// so we only return the args.
return args;
}

export function execModule(name: string, moduleArgs: string[], isolated = true): string[] {
export function execModule(name: string, moduleArgs: string[]): string[] {
const args = ['-m', name, ...moduleArgs];
if (isolated && getUseIsolationSetting()) {
args[0] = ISOLATED; // replace
}
// "code" isn't specific enough to know how to parse it,
// so we only return the args.
return args;
}

export function getVersion(): [string[], (out: string) => string] {
// There is no need to isolate this.
const args = ['--version'];

function parse(out: string): string {
Expand All @@ -47,7 +38,7 @@ export function getVersion(): [string[], (out: string) => string] {
}

export function getSysPrefix(): [string[], (out: string) => string] {
const args = maybeIsolated(['-c', 'import sys;print(sys.prefix)']);
const args = ['-c', 'import sys;print(sys.prefix)'];

function parse(out: string): string {
return out.trim();
Expand All @@ -57,7 +48,7 @@ export function getSysPrefix(): [string[], (out: string) => string] {
}

export function getExecutable(): [string[], (out: string) => string] {
const args = maybeIsolated(['-c', 'import sys;print(sys.executable)']);
const args = ['-c', 'import sys;print(sys.executable)'];

function parse(out: string): string {
return out.trim();
Expand All @@ -70,7 +61,7 @@ export function getSitePackages(): [string[], (out: string) => string] {
// On windows we also need the libs path (second item will
// return c:\xxx\lib\site-packages). This is returned by
// the following: get_python_lib
const args = maybeIsolated(['-c', 'from distutils.sysconfig import get_python_lib; print(get_python_lib())']);
const args = ['-c', 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'];

function parse(out: string): string {
return out.trim();
Expand All @@ -80,7 +71,7 @@ export function getSitePackages(): [string[], (out: string) => string] {
}

export function getUserSitePackages(): [string[], (out: string) => string] {
const args = maybeIsolated(['site', '--user-site']);
const args = ['site', '--user-site'];

function parse(out: string): string {
return out.trim();
Expand All @@ -90,7 +81,6 @@ export function getUserSitePackages(): [string[], (out: string) => string] {
}

export function isValid(): [string[], (out: string) => boolean] {
// There is no need to isolate this.
const args = ['-c', 'print(1234)'];

function parse(out: string): boolean {
Expand All @@ -101,7 +91,7 @@ export function isValid(): [string[], (out: string) => boolean] {
}

export function isModuleInstalled(name: string): [string[], (out: string) => boolean] {
const args = maybeIsolated(['-c', `import ${name}`]);
const args = ['-c', `import ${name}`];

function parse(_out: string): boolean {
// If the command did not fail then the module is installed.
Expand All @@ -112,7 +102,7 @@ export function isModuleInstalled(name: string): [string[], (out: string) => boo
}

export function getModuleVersion(name: string): [string[], (out: string) => string] {
const args = maybeIsolated(['-c', `import ${name}; print(${name}.__version__)`]);
const args = ['-c', `import ${name}; print(${name}.__version__)`];

function parse(out: string): string {
return out.trim();
Expand Down
1 change: 0 additions & 1 deletion src/client/common/process/internal/scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ import { EXTENSION_ROOT_DIR } from '../../../constants';

// It is simpler to hard-code it instead of using vscode.ExtensionContext.extensionPath.
export const _SCRIPTS_DIR = path.join(EXTENSION_ROOT_DIR, 'pythonFiles');
export const _ISOLATED = path.join(_SCRIPTS_DIR, 'pyvsc-run-isolated.py');
45 changes: 12 additions & 33 deletions src/client/common/process/internal/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,10 @@
// Licensed under the MIT License.

import * as path from 'path';
import { workspace } from 'vscode';
import { _ISOLATED, _SCRIPTS_DIR } from './constants';
import { _SCRIPTS_DIR } from './constants';
import { CompletionResponse, SymbolProviderSymbols } from './types';

const SCRIPTS_DIR = _SCRIPTS_DIR;
const ISOLATED = _ISOLATED;

// Re-export it so external modules can use it too.
export { _ISOLATED } from './constants';

export function getUseIsolationSetting(): boolean {
try {
return workspace.getConfiguration('python').get<boolean>('useIsolation', true);
} catch (ex) {
// If we can't get the setting for any reason we assume default
return true;
}
}

export function maybeIsolated(args: string[]): string[] {
if (getUseIsolationSetting()) {
args.splice(0, 0, ISOLATED);
}
return args;
}

// "scripts" contains everything relevant to the scripts found under
// the top-level "pythonFiles" directory. Each of those scripts has
Expand Down Expand Up @@ -65,7 +44,7 @@ export type InterpreterInfoJson = {

export function interpreterInfo(): [string[], (out: string) => InterpreterInfoJson] {
const script = path.join(SCRIPTS_DIR, 'interpreterInfo.py');
const args = maybeIsolated([script]);
const args = [script];

function parse(out: string): InterpreterInfoJson {
let json: InterpreterInfoJson;
Expand All @@ -84,7 +63,7 @@ export function interpreterInfo(): [string[], (out: string) => InterpreterInfoJs

export function completion(jediPath?: string): [string[], (out: string) => CompletionResponse[]] {
const script = path.join(SCRIPTS_DIR, 'completion.py');
const args = maybeIsolated([script]);
const args = [script];
if (jediPath) {
args.push('custom');
args.push(jediPath);
Expand All @@ -101,7 +80,7 @@ export function completion(jediPath?: string): [string[], (out: string) => Compl

export function sortImports(filename: string, sortArgs?: string[]): [string[], (out: string) => string] {
const script = path.join(SCRIPTS_DIR, 'sortImports.py');
const args = maybeIsolated([script, filename, '--diff']);
const args = [script, filename, '--diff'];
if (sortArgs) {
args.push(...sortArgs);
}
Expand All @@ -118,7 +97,7 @@ export function sortImports(filename: string, sortArgs?: string[]): [string[], (

export function refactor(root: string): [string[], (out: string) => Record<string, unknown>[]] {
const script = path.join(SCRIPTS_DIR, 'refactor.py');
const args = maybeIsolated([script, root]);
const args = [script, root];

// TODO: Make the return type more specific, like we did
// with completion().
Expand All @@ -137,7 +116,7 @@ export function refactor(root: string): [string[], (out: string) => Record<strin

export function normalizeSelection(): [string[], (out: string) => string] {
const script = path.join(SCRIPTS_DIR, 'normalizeSelection.py');
const args = maybeIsolated([script]);
const args = [script];

function parse(out: string) {
// The text will be used as-is.
Expand All @@ -155,7 +134,7 @@ export function symbolProvider(
text?: string,
): [string[], (out: string) => SymbolProviderSymbols] {
const script = path.join(SCRIPTS_DIR, 'symbolProvider.py');
const args = maybeIsolated([script, filename]);
const args = [script, filename];
if (text) {
args.push(text);
}
Expand All @@ -171,7 +150,7 @@ export function symbolProvider(

export function printEnvVariables(): [string[], (out: string) => NodeJS.ProcessEnv] {
const script = path.join(SCRIPTS_DIR, 'printEnvVariables.py').fileToCommandArgument();
const args = maybeIsolated([script]);
const args = [script];

function parse(out: string): NodeJS.ProcessEnv {
return JSON.parse(out);
Expand All @@ -187,22 +166,22 @@ export function shell_exec(command: string, lockfile: string, shellArgs: string[
const script = path.join(SCRIPTS_DIR, 'shell_exec.py');
// We don't bother with a "parse" function since the output
// could be anything.
return maybeIsolated([
return [
script,
command.fileToCommandArgument(),
// The shell args must come after the command
// but before the lockfile.
...shellArgs,
lockfile.fileToCommandArgument(),
]);
];
}

// testlauncher.py

export function testlauncher(testArgs: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'testlauncher.py');
// There is no output to parse, so we do not return a function.
return maybeIsolated([script, ...testArgs]);
return [script, ...testArgs];
}

// visualstudio_py_testlauncher.py
Expand All @@ -218,5 +197,5 @@ export function visualstudio_py_testlauncher(testArgs: string[]): string[] {

export function tensorboardLauncher(args: string[]): string[] {
const script = path.join(SCRIPTS_DIR, 'tensorboard_launcher.py');
return maybeIsolated([script, ...args]);
return [script, ...args];
}
1 change: 0 additions & 1 deletion src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export interface IPythonSettings {
readonly languageServerIsDefault: boolean;
readonly defaultInterpreterPath: string;
readonly logging: ILoggingSettings;
readonly useIsolation: boolean;
readonly tensorBoard: ITensorBoardSettings | undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/testing/unittest/services/discoveryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TestDiscoveryService implements ITestDiscoveryService {
const runOptions: Options = {
// unittest needs to load modules in the workspace
// isolating it breaks unittest discovery
args: internalPython.execCode(pythonScript, false),
args: internalPython.execCode(pythonScript),
cwd: options.cwd,
workspaceFolder: options.workspaceFolder,
token: options.token,
Expand Down
4 changes: 2 additions & 2 deletions src/test/common/configSettings/configSettings.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ suite('Python Settings', async () => {
}

// boolean settings
for (const name of ['downloadLanguageServer', 'autoUpdateLanguageServer', 'useIsolation']) {
for (const name of ['downloadLanguageServer', 'autoUpdateLanguageServer']) {
config
.setup((c) => c.get<boolean>(name, true))

Expand Down Expand Up @@ -144,7 +144,7 @@ suite('Python Settings', async () => {
});

suite('Boolean settings', async () => {
['downloadLanguageServer', 'autoUpdateLanguageServer', 'globalModuleInstallation', 'useIsolation'].forEach(
['downloadLanguageServer', 'autoUpdateLanguageServer', 'globalModuleInstallation'].forEach(
async (settingName) => {
testIfValueIsUpdated(settingName, true);
},
Expand Down
3 changes: 1 addition & 2 deletions src/test/common/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ suite('Installer', () => {
const checkInstalledDef = createDeferred<boolean>();
processService.onExec((_file, args, _options, callback) => {
const moduleName = installer.translateProductToModuleName(product, ModuleNamePurpose.run);
// args[0] is pyvsc-run-isolated.py.
if (args.length > 1 && args[1] === '-c' && args[2] === `import ${moduleName}`) {
if (args.length > 1 && args[0] === '-c' && args[1] === `import ${moduleName}`) {
checkInstalledDef.resolve(true);
}
callback({ stdout: '' });
Expand Down
Loading