Skip to content

Commit

Permalink
support interpreter paths with spaces (#499)
Browse files Browse the repository at this point in the history
* support interpreter paths with spaces

* use fileToCommandArgumentForPythonExt and add test

* fix unnecessary edit

* switch to use path.join

* error fix

* fix path to match desired
  • Loading branch information
eleanorjboyd authored Nov 13, 2024
1 parent a0bc66d commit 9db85ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/extension/debugger/adapter/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Commands, EXTENSION_ROOT_DIR } from '../../common/constants';
import { Common, DebugConfigStrings, Interpreters } from '../../common/utils/localize';
import { IPersistentStateFactory } from '../../common/types';
import { ResolvedEnvironment } from '@vscode/python-extension';
import { fileToCommandArgumentForPythonExt } from '../../common/stringUtils';

// persistent state names, exported to make use of in testing
export enum debugStateKeys {
Expand Down Expand Up @@ -74,7 +75,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
sendTelemetryEvent(EventName.DEBUGGER_ATTACH_TO_LOCAL_PROCESS);
}

const executable = command.shift() ?? 'python';
let executable = command.shift() ?? 'python';

// "logToFile" is not handled directly by the adapter - instead, we need to pass
// the corresponding CLI switch when spawning it.
Expand All @@ -83,6 +84,7 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
if (configuration.debugAdapterPath !== undefined) {
const args = command.concat([configuration.debugAdapterPath, ...logArgs]);
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
executable = fileToCommandArgumentForPythonExt(executable);
return new DebugAdapterExecutable(executable, args);
}

Expand Down
23 changes: 22 additions & 1 deletion src/test/unittest/adapter/factory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ suite('Debugging - Adapter Factory', () => {

const nodeExecutable = undefined;
const debugAdapterPath = path.join(EXTENSION_ROOT_DIR, 'bundled', 'libs', 'debugpy', 'adapter');
const pythonPath = path.join('path', 'to', 'python', 'interpreter');
const pythonPath = 'path/to/python/interpreter';
const interpreter = {
architecture: Architecture.Unknown,
path: pythonPath,
Expand Down Expand Up @@ -291,6 +291,27 @@ suite('Debugging - Adapter Factory', () => {

assert.deepStrictEqual(descriptor, debugExecutable);
});
test('Add quotes to interpreter path with spaces', async () => {
const customAdapterPath = 'custom/debug/adapter/customAdapterPath';
const session = createSession({ debugAdapterPath: customAdapterPath });
const interpreterPathSpaces = 'path/to/python interpreter with spaces';
const interpreterPathSpacesQuoted = `"${interpreterPathSpaces}"`;
const debugExecutable = new DebugAdapterExecutable(interpreterPathSpacesQuoted, [customAdapterPath]);

getInterpreterDetailsStub.resolves({ path: [interpreterPathSpaces] });
const interpreterSpacePath = {
architecture: Architecture.Unknown,
path: interpreterPathSpaces,
sysPrefix: '',
sysVersion: '',
envType: 'Unknow',
version: new SemVer('3.7.4-test'),
};
resolveEnvironmentStub.withArgs(interpreterPathSpaces).resolves(interpreterSpacePath);
const descriptor = await factory.createDebugAdapterDescriptor(session, nodeExecutable);

assert.deepStrictEqual(descriptor, debugExecutable);
});

test('Use "debugAdapterPython" when specified', async () => {
const session = createSession({ debugAdapterPython: '/bin/custompy' });
Expand Down

0 comments on commit 9db85ed

Please sign in to comment.