Skip to content

Commit 3b114e3

Browse files
authored
Use older way of launching debugger when using conda less than 4.9.0 (#18451)
1 parent 94d604a commit 3b114e3

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

news/2 Fixes/18436.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Revert to old way of running debugger if conda version less than 4.9.0.

src/client/debugger/extension/adapter/factory.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { IApplicationShell } from '../../../common/application/types';
1616
import { EXTENSION_ROOT_DIR } from '../../../constants';
1717
import { IInterpreterService } from '../../../interpreter/contracts';
18-
import { traceVerbose } from '../../../logging';
18+
import { traceLog, traceVerbose } from '../../../logging';
1919
import { Conda } from '../../../pythonEnvironments/common/environmentManagers/conda';
2020
import { EnvironmentType, PythonEnvironment } from '../../../pythonEnvironments/info';
2121
import { sendTelemetryEvent } from '../../../telemetry';
@@ -49,8 +49,14 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
4949

5050
if (configuration.request === 'attach') {
5151
if (configuration.connect !== undefined) {
52+
traceLog(
53+
`Connecting to DAP Server at: ${configuration.connect.host ?? '127.0.0.1'}:${
54+
configuration.connect.port
55+
}`,
56+
);
5257
return new DebugAdapterServer(configuration.connect.port, configuration.connect.host ?? '127.0.0.1');
5358
} else if (configuration.port !== undefined) {
59+
traceLog(`Connecting to DAP Server at: ${configuration.host ?? '127.0.0.1'}:${configuration.port}`);
5460
return new DebugAdapterServer(configuration.port, configuration.host ?? '127.0.0.1');
5561
} else if (configuration.listen === undefined && configuration.processId === undefined) {
5662
throw new Error('"request":"attach" requires either "connect", "listen", or "processId"');
@@ -70,10 +76,9 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
7076
const logArgs = configuration.logToFile ? ['--log-dir', EXTENSION_ROOT_DIR] : [];
7177

7278
if (configuration.debugAdapterPath !== undefined) {
73-
return new DebugAdapterExecutable(
74-
executable,
75-
command.concat([configuration.debugAdapterPath, ...logArgs]),
76-
);
79+
const args = command.concat([configuration.debugAdapterPath, ...logArgs]);
80+
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
81+
return new DebugAdapterExecutable(executable, args);
7782
}
7883

7984
const debuggerAdapterPathToUse = path.join(
@@ -85,8 +90,10 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
8590
'adapter',
8691
);
8792

93+
const args = command.concat([debuggerAdapterPathToUse, ...logArgs]);
94+
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
8895
sendTelemetryEvent(EventName.DEBUG_ADAPTER_USING_WHEELS_PATH, undefined, { usingWheels: true });
89-
return new DebugAdapterExecutable(executable, command.concat([debuggerAdapterPathToUse, ...logArgs]));
96+
return new DebugAdapterExecutable(executable, args);
9097
}
9198

9299
// Unlikely scenario.
@@ -136,10 +143,16 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
136143
return this.getExecutableCommand(interpreters[0]);
137144
}
138145

146+
private async getCondaCommand(): Promise<Conda | undefined> {
147+
const condaCommand = await Conda.getConda();
148+
const isCondaRunSupported = await condaCommand?.isCondaRunSupported();
149+
return isCondaRunSupported ? condaCommand : undefined;
150+
}
151+
139152
private async getExecutableCommand(interpreter: PythonEnvironment | undefined): Promise<string[]> {
140153
if (interpreter) {
141154
if (interpreter.envType === EnvironmentType.Conda) {
142-
const condaCommand = await Conda.getConda();
155+
const condaCommand = await this.getCondaCommand();
143156
if (condaCommand) {
144157
if (interpreter.envName) {
145158
return [

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,12 @@ export class Conda {
447447
traceError(`Unable to parse version of Conda, ${versionString}`);
448448
return new SemVer('0.0.1');
449449
}
450+
451+
public async isCondaRunSupported(): Promise<boolean> {
452+
const condaVersion = await this.getCondaVersion();
453+
if (condaVersion && lt(condaVersion, CONDA_RUN_VERSION)) {
454+
return false;
455+
}
456+
return true;
457+
}
450458
}

0 commit comments

Comments
 (0)