Skip to content

Commit 054407d

Browse files
author
Kartik Raj
authored
Revert using conda run for conda environments for running python files (#18661)
* Revert "Use conda run for conda environments for running python files (#18520)" This reverts commit 8fc8648. * Revert "Fix unit tests related to terminal code execution (#18549)" This reverts commit c5e5979. * News entry
1 parent d1f757b commit 054407d

File tree

10 files changed

+32
-202
lines changed

10 files changed

+32
-202
lines changed

news/2 Fixes/18634.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes regression caused due to using `conda run` for executing files.

src/client/common/process/pythonEnvironment.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,9 @@ export async function createCondaEnv(
149149
// These are used to generate the deps.
150150
procs: IProcessService,
151151
fs: IFileSystem,
152-
executeAsAProcess?: boolean,
153152
): Promise<PythonEnvironment | undefined> {
154153
const conda = await Conda.getConda();
155-
const pythonArgv = await conda?.getRunPythonArgs(
156-
{ name: condaInfo.name, prefix: condaInfo.path },
157-
executeAsAProcess,
158-
);
154+
const pythonArgv = await conda?.getRunPythonArgs({ name: condaInfo.name, prefix: condaInfo.path });
159155
if (!pythonArgv) {
160156
return undefined;
161157
}

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
7777
}
7878
const processService: IProcessService = await this.processServiceFactory.create(options.resource);
7979

80-
const condaExecutionService = await this.createCondaExecutionService(
81-
pythonPath,
82-
processService,
83-
options.executeAsAProcess,
84-
);
80+
const condaExecutionService = await this.createCondaExecutionService(pythonPath, processService);
8581
if (condaExecutionService) {
8682
return condaExecutionService;
8783
}
@@ -129,20 +125,13 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
129125
public async createCondaExecutionService(
130126
pythonPath: string,
131127
processService: IProcessService,
132-
executeAsAProcess?: boolean,
133128
): Promise<IPythonExecutionService | undefined> {
134129
const condaLocatorService = this.serviceContainer.get<IComponentAdapter>(IComponentAdapter);
135130
const [condaEnvironment] = await Promise.all([condaLocatorService.getCondaEnvironment(pythonPath)]);
136131
if (!condaEnvironment) {
137132
return undefined;
138133
}
139-
const env = await createCondaEnv(
140-
condaEnvironment,
141-
pythonPath,
142-
processService,
143-
this.fileSystem,
144-
executeAsAProcess,
145-
);
134+
const env = await createCondaEnv(condaEnvironment, pythonPath, processService, this.fileSystem);
146135
if (!env) {
147136
return undefined;
148137
}

src/client/common/process/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ export const IPythonExecutionFactory = Symbol('IPythonExecutionFactory');
6565
export type ExecutionFactoryCreationOptions = {
6666
resource?: Uri;
6767
pythonPath?: string;
68-
/**
69-
* Whether to execute using `NodeJS.child_process` API, considered `true` as default.
70-
*/
71-
executeAsAProcess?: boolean;
7268
};
7369
export type ExecutionFactoryCreateWithEnvironmentOptions = {
7470
resource?: Uri;

src/client/pythonEnvironments/common/environmentManagers/conda.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class Conda {
405405
return envList.find((e) => isParentPath(executable, e.prefix));
406406
}
407407

408-
public async getRunPythonArgs(env: CondaEnvInfo, executeAsAProcess = true): Promise<string[] | undefined> {
408+
public async getRunPythonArgs(env: CondaEnvInfo): Promise<string[] | undefined> {
409409
const condaVersion = await this.getCondaVersion();
410410
if (condaVersion && lt(condaVersion, CONDA_RUN_VERSION)) {
411411
return undefined;
@@ -416,11 +416,7 @@ export class Conda {
416416
} else {
417417
args.push('-p', env.prefix);
418418
}
419-
const pythonArgs = [this.command, 'run', ...args, '--no-capture-output', '--live-stream', 'python'];
420-
if (executeAsAProcess) {
421-
pythonArgs.push(OUTPUT_MARKER_SCRIPT);
422-
}
423-
return pythonArgs;
419+
return [this.command, 'run', ...args, '--no-capture-output', '--live-stream', 'python', OUTPUT_MARKER_SCRIPT];
424420
}
425421

426422
/**

src/client/terminals/codeExecution/djangoShellCodeExecution.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Disposable, Uri } from 'vscode';
99
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../common/application/types';
1010
import '../../common/extensions';
1111
import { IFileSystem, IPlatformService } from '../../common/platform/types';
12-
import { IPythonExecutionFactory } from '../../common/process/types';
1312
import { ITerminalServiceFactory } from '../../common/terminal/types';
1413
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
1514
import { copyPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
@@ -27,16 +26,8 @@ export class DjangoShellCodeExecutionProvider extends TerminalCodeExecutionProvi
2726
@inject(ICommandManager) commandManager: ICommandManager,
2827
@inject(IFileSystem) fileSystem: IFileSystem,
2928
@inject(IDisposableRegistry) disposableRegistry: Disposable[],
30-
@inject(IPythonExecutionFactory) pythonExecutionFactory: IPythonExecutionFactory,
3129
) {
32-
super(
33-
terminalServiceFactory,
34-
configurationService,
35-
workspace,
36-
disposableRegistry,
37-
platformService,
38-
pythonExecutionFactory,
39-
);
30+
super(terminalServiceFactory, configurationService, workspace, disposableRegistry, platformService);
4031
this.terminalTitle = 'Django Shell';
4132
disposableRegistry.push(new DjangoContextInitializer(documentManager, workspace, fileSystem, commandManager));
4233
}

src/client/terminals/codeExecution/repl.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { inject, injectable } from 'inversify';
77
import { Disposable } from 'vscode';
88
import { IWorkspaceService } from '../../common/application/types';
99
import { IPlatformService } from '../../common/platform/types';
10-
import { IPythonExecutionFactory } from '../../common/process/types';
1110
import { ITerminalServiceFactory } from '../../common/terminal/types';
1211
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
1312
import { TerminalCodeExecutionProvider } from './terminalCodeExecution';
@@ -20,16 +19,8 @@ export class ReplProvider extends TerminalCodeExecutionProvider {
2019
@inject(IWorkspaceService) workspace: IWorkspaceService,
2120
@inject(IDisposableRegistry) disposableRegistry: Disposable[],
2221
@inject(IPlatformService) platformService: IPlatformService,
23-
@inject(IPythonExecutionFactory) pythonExecutionFactory: IPythonExecutionFactory,
2422
) {
25-
super(
26-
terminalServiceFactory,
27-
configurationService,
28-
workspace,
29-
disposableRegistry,
30-
platformService,
31-
pythonExecutionFactory,
32-
);
23+
super(terminalServiceFactory, configurationService, workspace, disposableRegistry, platformService);
3324
this.terminalTitle = 'REPL';
3425
}
3526
}

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Disposable, Uri } from 'vscode';
99
import { IWorkspaceService } from '../../common/application/types';
1010
import '../../common/extensions';
1111
import { IPlatformService } from '../../common/platform/types';
12-
import { IPythonExecutionFactory } from '../../common/process/types';
1312
import { ITerminalService, ITerminalServiceFactory } from '../../common/terminal/types';
1413
import { IConfigurationService, IDisposableRegistry } from '../../common/types';
1514
import { buildPythonExecInfo, PythonExecInfo } from '../../pythonEnvironments/exec';
@@ -27,7 +26,6 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
2726
@inject(IWorkspaceService) protected readonly workspace: IWorkspaceService,
2827
@inject(IDisposableRegistry) protected readonly disposables: Disposable[],
2928
@inject(IPlatformService) protected readonly platformService: IPlatformService,
30-
@inject(IPythonExecutionFactory) private readonly pythonExecutionFactory: IPythonExecutionFactory,
3129
) {}
3230

3331
public async executeFile(file: Uri) {
@@ -63,12 +61,11 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
6361

6462
public async getExecutableInfo(resource?: Uri, args: string[] = []): Promise<PythonExecInfo> {
6563
const pythonSettings = this.configurationService.getSettings(resource);
66-
const executionFactory = await this.pythonExecutionFactory.create({ resource, executeAsAProcess: false });
67-
const execInfo = executionFactory.getExecutionInfo();
68-
const pythonArgs = execInfo.args;
69-
const command = this.platformService.isWindows ? execInfo.command.replace(/\\/g, '/') : execInfo.command;
64+
const command = this.platformService.isWindows
65+
? pythonSettings.pythonPath.replace(/\\/g, '/')
66+
: pythonSettings.pythonPath;
7067
const launchArgs = pythonSettings.terminal.launchArgs;
71-
return buildPythonExecInfo(command, [...pythonArgs, ...launchArgs, ...args]);
68+
return buildPythonExecInfo(command, [...launchArgs, ...args]);
7269
}
7370

7471
// Overridden in subclasses, see djangoShellCodeExecution.ts

src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../c
1010
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
1111
import { createCondaEnv } from '../../../client/common/process/pythonEnvironment';
1212
import { createPythonProcessService } from '../../../client/common/process/pythonProcess';
13-
import {
14-
IProcessService,
15-
IPythonExecutionFactory,
16-
IPythonExecutionService,
17-
} from '../../../client/common/process/types';
13+
import { IProcessService, IPythonExecutionFactory } from '../../../client/common/process/types';
1814
import { ITerminalService, ITerminalServiceFactory } from '../../../client/common/terminal/types';
1915
import { IConfigurationService, IPythonSettings, ITerminalSettings } from '../../../client/common/types';
2016
import { DjangoShellCodeExecutionProvider } from '../../../client/terminals/codeExecution/djangoShellCodeExecution';
@@ -23,7 +19,6 @@ import { PYTHON_PATH } from '../../common';
2319
import { Conda, CONDA_RUN_VERSION } from '../../../client/pythonEnvironments/common/environmentManagers/conda';
2420
import { SemVer } from 'semver';
2521
import assert from 'assert';
26-
import { PythonExecInfo } from '../../../client/pythonEnvironments/exec';
2722

2823
suite('Terminal - Django Shell Code Execution', () => {
2924
let executor: ICodeExecutionService;
@@ -62,7 +57,6 @@ suite('Terminal - Django Shell Code Execution', () => {
6257
commandManager.object,
6358
fileSystem.object,
6459
disposables,
65-
pythonExecutionFactory.object,
6660
);
6761

6862
terminalFactory.setup((f) => f.getTerminalService(TypeMoq.It.isAny())).returns(() => terminalService.object);
@@ -91,14 +85,7 @@ suite('Terminal - Django Shell Code Execution', () => {
9185
resource?: Uri,
9286
) {
9387
platform.setup((p) => p.isWindows).returns(() => isWindows);
94-
const executionService = TypeMoq.Mock.ofType<IPythonExecutionService>();
95-
pythonExecutionFactory
96-
.setup((p) => p.create(TypeMoq.It.isAny()))
97-
.returns(() => Promise.resolve(executionService.object));
98-
executionService.setup((p) => (p as any).then).returns(() => undefined);
99-
executionService
100-
.setup((e) => e.getExecutionInfo())
101-
.returns(() => (({ command: pythonPath, args: [] } as unknown) as PythonExecInfo));
88+
settings.setup((s) => s.pythonPath).returns(() => pythonPath);
10289
terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs);
10390

10491
const replCommandArgs = await (executor as DjangoShellCodeExecutionProvider).getExecutableInfo(resource);
@@ -217,14 +204,7 @@ suite('Terminal - Django Shell Code Execution', () => {
217204
condaEnv: { name: string; path: string },
218205
resource?: Uri,
219206
) {
220-
const executionService = TypeMoq.Mock.ofType<IPythonExecutionService>();
221-
pythonExecutionFactory
222-
.setup((p) => p.create(TypeMoq.It.isAny()))
223-
.returns(() => Promise.resolve(executionService.object));
224-
executionService.setup((p) => (p as any).then).returns(() => undefined);
225-
executionService
226-
.setup((e) => e.getExecutionInfo())
227-
.returns(() => (({ command: pythonPath, args: [] } as unknown) as PythonExecInfo));
207+
settings.setup((s) => s.pythonPath).returns(() => pythonPath);
228208
terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs);
229209

230210
const condaFile = 'conda';

0 commit comments

Comments
 (0)