Skip to content

Commit

Permalink
Use older way of launching debugger when using conda less than 4.9.0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Feb 7, 2022
1 parent 0856eb2 commit fca6fe3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/18436.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert to old way of running debugger if conda version less than 4.9.0.
27 changes: 20 additions & 7 deletions src/client/debugger/extension/adapter/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { IApplicationShell } from '../../../common/application/types';
import { EXTENSION_ROOT_DIR } from '../../../constants';
import { IInterpreterService } from '../../../interpreter/contracts';
import { traceVerbose } from '../../../logging';
import { traceLog, traceVerbose } from '../../../logging';
import { Conda } from '../../../pythonEnvironments/common/environmentManagers/conda';
import { EnvironmentType, PythonEnvironment } from '../../../pythonEnvironments/info';
import { sendTelemetryEvent } from '../../../telemetry';
Expand Down Expand Up @@ -49,8 +49,14 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac

if (configuration.request === 'attach') {
if (configuration.connect !== undefined) {
traceLog(
`Connecting to DAP Server at: ${configuration.connect.host ?? '127.0.0.1'}:${
configuration.connect.port
}`,
);
return new DebugAdapterServer(configuration.connect.port, configuration.connect.host ?? '127.0.0.1');
} else if (configuration.port !== undefined) {
traceLog(`Connecting to DAP Server at: ${configuration.host ?? '127.0.0.1'}:${configuration.port}`);
return new DebugAdapterServer(configuration.port, configuration.host ?? '127.0.0.1');
} else if (configuration.listen === undefined && configuration.processId === undefined) {
throw new Error('"request":"attach" requires either "connect", "listen", or "processId"');
Expand All @@ -70,10 +76,9 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
const logArgs = configuration.logToFile ? ['--log-dir', EXTENSION_ROOT_DIR] : [];

if (configuration.debugAdapterPath !== undefined) {
return new DebugAdapterExecutable(
executable,
command.concat([configuration.debugAdapterPath, ...logArgs]),
);
const args = command.concat([configuration.debugAdapterPath, ...logArgs]);
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
return new DebugAdapterExecutable(executable, args);
}

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

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

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

private async getCondaCommand(): Promise<Conda | undefined> {
const condaCommand = await Conda.getConda();
const isCondaRunSupported = await condaCommand?.isCondaRunSupported();
return isCondaRunSupported ? condaCommand : undefined;
}

private async getExecutableCommand(interpreter: PythonEnvironment | undefined): Promise<string[]> {
if (interpreter) {
if (interpreter.envType === EnvironmentType.Conda) {
const condaCommand = await Conda.getConda();
const condaCommand = await this.getCondaCommand();
if (condaCommand) {
if (interpreter.envName) {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,4 +447,12 @@ export class Conda {
traceError(`Unable to parse version of Conda, ${versionString}`);
return new SemVer('0.0.1');
}

public async isCondaRunSupported(): Promise<boolean> {
const condaVersion = await this.getCondaVersion();
if (condaVersion && lt(condaVersion, CONDA_RUN_VERSION)) {
return false;
}
return true;
}
}

0 comments on commit fca6fe3

Please sign in to comment.