Skip to content

Commit dbabe30

Browse files
authored
Always use bundled version of PTVSD in the debugger (microsoft#3438)
* Add news entry * Fixed tests * Tweak news entry * Tweak news entry's code block type
1 parent 828e53e commit dbabe30

8 files changed

Lines changed: 40 additions & 13 deletions

File tree

‎news/2 Fixes/3283.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Always use bundled version of [`ptvsd`](https://github.com/microsoft/ptvsd), unless specified.
2+
To use a custom version of `ptvsd` in the debugger, add `customDebugger` into your `launch.json` configuration as follows:
3+
```json
4+
"type": "python",
5+
"request": "launch",
6+
"customDebugger": true
7+
```

‎pythonFiles/experimental/ptvsd_launcher.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
import sys
77
import traceback
88

9+
useCustomPtvsd = sys.argv[1] == '--custom'
10+
ptvsdArgs = sys.argv[:]
11+
ptvsdArgs.pop(1)
12+
913
# Load the debugger package
1014
try:
1115
ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'ptvsd')
12-
sys.path.append(ptvs_lib_path)
16+
if useCustomPtvsd:
17+
sys.path.append(ptvs_lib_path)
18+
else:
19+
sys.path.insert(0, ptvs_lib_path)
1320
try:
1421
import ptvsd
1522
import ptvsd.debugger as vspd
@@ -35,4 +42,4 @@
3542
if ptvs_lib_path:
3643
sys.path.remove(ptvs_lib_path)
3744

38-
main(sys.argv)
45+
main(ptvsdArgs)

‎src/client/debugger/debugAdapter/DebugClients/launcherProvider.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ import { IDebugLauncherScriptProvider, IRemoteDebugLauncherScriptProvider, Local
1212
const script = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental', 'ptvsd_launcher.py');
1313
export class NoDebugLauncherScriptProvider implements IDebugLauncherScriptProvider<LocalDebugOptions> {
1414
public getLauncherArgs(options: LocalDebugOptions): string[] {
15-
return [script, '--nodebug', '--client', '--host', options.host, '--port', options.port.toString()];
15+
const customDebugger = options.customDebugger ? '--custom' : '--default';
16+
return [script, customDebugger, '--nodebug', '--client', '--host', options.host, '--port', options.port.toString()];
1617
}
1718
}
1819

1920
export class DebuggerLauncherScriptProvider implements IDebugLauncherScriptProvider<LocalDebugOptions> {
2021
public getLauncherArgs(options: LocalDebugOptions): string[] {
21-
return [script, '--client', '--host', options.host, '--port', options.port.toString()];
22+
const customDebugger = options.customDebugger ? '--custom' : '--default';
23+
return [script, customDebugger, '--client', '--host', options.host, '--port', options.port.toString()];
2224
}
2325
}
2426

2527
export class RemoteDebuggerLauncherScriptProvider implements IRemoteDebugLauncherScriptProvider {
2628
public getLauncherArgs(options: RemoteDebugOptions): string[] {
2729
const waitArgs = options.waitUntilDebuggerAttaches ? ['--wait'] : [];
28-
return [script, '--host', options.host, '--port', options.port.toString()].concat(waitArgs);
30+
return [script, '--default', '--host', options.host, '--port', options.port.toString()].concat(waitArgs);
2931
}
3032
}

‎src/client/debugger/debugAdapter/DebugClients/localDebugClientV2.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class LocalDebugClientV2 extends LocalDebugClient {
1313
super(args, debugSession, canLaunchTerminal, launcherScriptProvider);
1414
}
1515
protected buildDebugArguments(cwd: string, debugPort: number): string[] {
16-
return this.launcherScriptProvider.getLauncherArgs({ host: 'localhost', port: debugPort });
16+
return this.launcherScriptProvider.getLauncherArgs({ host: 'localhost', port: debugPort, customDebugger: this.args.customDebugger });
1717
}
1818
protected buildStandardArguments() {
1919
const programArgs = Array.isArray(this.args.args) && this.args.args.length > 0 ? this.args.args : [];

‎src/client/debugger/debugAdapter/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Disposable } from 'vscode';
99
import { Logger } from 'vscode-debugadapter';
1010
import { Message } from 'vscode-debugadapter/lib/messages';
1111

12-
export type LocalDebugOptions = { port: number; host: string };
12+
export type LocalDebugOptions = { port: number; host: string; customDebugger?: boolean };
1313
export type RemoteDebugOptions = LocalDebugOptions & { waitUntilDebuggerAttaches: boolean };
1414

1515
export interface IDebugLauncherScriptProvider<T> {

‎src/client/debugger/types.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface IKnownAttachDebugArguments extends ICommonDebugArguments {
4242
localRoot?: string;
4343
remoteRoot?: string;
4444
pathMappings?: { localRoot: string; remoteRoot: string }[];
45+
customDebugger?: boolean;
4546
}
4647

4748
export interface IKnownLaunchRequestArguments extends ICommonDebugArguments {

‎src/test/debugger/debugAdapter/debugClients/launcherProvider.unit.test.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,32 @@ suite('Debugger - Launcher Script Provider', () => {
1717
});
1818
test('Test debug launcher args', async () => {
1919
const args = new DebuggerLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234 });
20-
const expectedArgs = [expectedPath, '--client', '--host', 'something', '--port', '1234'];
20+
const expectedArgs = [expectedPath, '--default', '--client', '--host', 'something', '--port', '1234'];
2121
expect(args).to.be.deep.equal(expectedArgs);
2222
});
2323
test('Test non-debug launcher args', async () => {
2424
const args = new NoDebugLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234 });
25-
const expectedArgs = [expectedPath, '--nodebug', '--client', '--host', 'something', '--port', '1234'];
25+
const expectedArgs = [expectedPath, '--default', '--nodebug', '--client', '--host', 'something', '--port', '1234'];
26+
expect(args).to.be.deep.equal(expectedArgs);
27+
});
28+
test('Test debug launcher args and custom ptvsd', async () => {
29+
const args = new DebuggerLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234, customDebugger: true });
30+
const expectedArgs = [expectedPath, '--custom', '--client', '--host', 'something', '--port', '1234'];
31+
expect(args).to.be.deep.equal(expectedArgs);
32+
});
33+
test('Test non-debug launcher args and custom ptvsd', async () => {
34+
const args = new NoDebugLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234, customDebugger: true });
35+
const expectedArgs = [expectedPath, '--custom', '--nodebug', '--client', '--host', 'something', '--port', '1234'];
2636
expect(args).to.be.deep.equal(expectedArgs);
2737
});
2838
test('Test remote debug launcher args (and do not wait for debugger to attach)', async () => {
2939
const args = new RemoteDebuggerLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234, waitUntilDebuggerAttaches: false });
30-
const expectedArgs = [expectedPath, '--host', 'something', '--port', '1234'];
40+
const expectedArgs = [expectedPath, '--default', '--host', 'something', '--port', '1234'];
3141
expect(args).to.be.deep.equal(expectedArgs);
3242
});
3343
test('Test remote debug launcher args (and wait for debugger to attach)', async () => {
3444
const args = new RemoteDebuggerLauncherScriptProvider().getLauncherArgs({ host: 'something', port: 1234, waitUntilDebuggerAttaches: true });
35-
const expectedArgs = [expectedPath, '--host', 'something', '--port', '1234', '--wait'];
45+
const expectedArgs = [expectedPath, '--default', '--host', 'something', '--port', '1234', '--wait'];
3646
expect(args).to.be.deep.equal(expectedArgs);
3747
});
3848
});

‎src/test/extension.unit.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const expectedPath = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'experimental'
1515
suite('Extension API Debugger', () => {
1616
test('Test debug launcher args (no-wait)', async () => {
1717
const args = await buildApi(Promise.resolve()).debug.getRemoteLauncherCommand('something', 1234, false);
18-
const expectedArgs = [expectedPath, '--host', 'something', '--port', '1234'];
18+
const expectedArgs = [expectedPath, '--default', '--host', 'something', '--port', '1234'];
1919
expect(args).to.be.deep.equal(expectedArgs);
2020
});
2121
test('Test debug launcher args (wait)', async () => {
2222
const args = await buildApi(Promise.resolve()).debug.getRemoteLauncherCommand('something', 1234, true);
23-
const expectedArgs = [expectedPath, '--host', 'something', '--port', '1234', '--wait'];
23+
const expectedArgs = [expectedPath, '--default', '--host', 'something', '--port', '1234', '--wait'];
2424
expect(args).to.be.deep.equal(expectedArgs);
2525
});
2626
});

0 commit comments

Comments
 (0)