Skip to content

Commit 93761d0

Browse files
paulacamargo25wesm
authored andcommitted
Use python debugger api (microsoft/vscode-python#23211)
- Use Python Debugger API - Use debugpy from Python Debugger - Remove debugpy
1 parent c5f1cdc commit 93761d0

File tree

22 files changed

+82
-161
lines changed

22 files changed

+82
-161
lines changed

extensions/positron-python/.github/ISSUE_TEMPLATE/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ contact_links:
99
- name: 'Jupyter'
1010
url: https://github.com/microsoft/vscode-jupyter/issues
1111
about: 'For issues relating to the Jupyter extension (including the interactive window)'
12-
- name: 'Debugpy'
13-
url: https://github.com/microsoft/debugpy/issues
14-
about: 'For issues relating to the debugpy debugger'
12+
- name: 'Python Debugger'
13+
url: https://github.com/microsoft/vscode-python-debugger/issues
14+
about: 'For issues relating to the Python debugger'
1515
- name: Help/Support
1616
url: https://github.com/microsoft/vscode-python/discussions/categories/q-a
1717
about: 'Having trouble with the extension? Need help getting something to work?'

extensions/positron-python/.github/actions/build-vsix/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ runs:
4040
run: python -m pip install wheel nox
4141
shell: bash
4242

43-
- name: Install Python Extension dependencies (jedi, debugpy, etc.)
43+
- name: Install Python Extension dependencies (jedi, etc.)
4444
run: nox --session install_python_libs
4545
shell: bash
4646

extensions/positron-python/.github/actions/smoke-tests/action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ runs:
3939
- name: pip install system test requirements
4040
run: |
4141
python -m pip install --upgrade -r build/test-requirements.txt
42-
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --implementation py --no-deps --upgrade --pre debugpy
4342
shell: bash
4443

4544
# Bits from the VSIX are reused by smokeTest.ts to speed things up.

extensions/positron-python/.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ jobs:
9494

9595
- name: Install other Python requirements
9696
run: |
97-
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
9897
python -m pip install --upgrade -r build/test-requirements.txt
9998
10099
- name: Run Pyright
@@ -192,7 +191,7 @@ jobs:
192191
- name: Install build pre-requisite
193192
run: python -m pip install wheel nox
194193

195-
- name: Install Python Extension dependencies (jedi, debugpy, etc.)
194+
- name: Install Python Extension dependencies (jedi, etc.)
196195
run: nox --session install_python_libs
197196

198197
- name: Install test requirements

extensions/positron-python/.github/workflows/pr-check.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ jobs:
6868

6969
- name: Install other Python requirements
7070
run: |
71-
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
7271
python -m pip install --upgrade -r build/test-requirements.txt
7372
7473
- name: Run Pyright
@@ -180,7 +179,7 @@ jobs:
180179
- name: Install build pre-requisite
181180
run: python -m pip install wheel nox
182181

183-
- name: Install Python Extension dependencies (jedi, debugpy, etc.)
182+
- name: Install Python Extension dependencies (jedi, etc.)
184183
run: nox --session install_python_libs
185184

186185
- name: Install test requirements
@@ -380,11 +379,6 @@ jobs:
380379
- name: Install Jedi requirements
381380
run: python scripts/vendor.py
382381

383-
- name: Install debugpy
384-
run: |
385-
# We need to have debugpy so that tests relying on it keep passing, but we don't need install_debugpy's logic in the test phase.
386-
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --implementation py --no-deps --upgrade --pre debugpy
387-
388382
- name: Install test requirements
389383
run: python -m pip install --upgrade -r build/test-requirements.txt
390384

extensions/positron-python/build/azure-pipeline.pre-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extends:
5454

5555
- script: |
5656
nox --session install_python_libs
57-
displayName: Install debugpy, Jedi, get-pip, etc
57+
displayName: Install Jedi, get-pip, etc
5858
5959
- script: |
6060
python ./build/update_ext_version.py --for-publishing

extensions/positron-python/build/azure-pipeline.stable.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extends:
4949

5050
- script: |
5151
nox --session install_python_libs
52-
displayName: Install debugpy, Jedi, get-pip, etc
52+
displayName: Install Jedi, get-pip, etc
5353
5454
- script: |
5555
python ./build/update_ext_version.py --release --for-publishing

extensions/positron-python/noxfile.py

-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ def install_python_libs(session: nox.Session):
3232

3333
session.install("packaging")
3434

35-
# Install debugger
36-
session.run(
37-
"python",
38-
"./python_files/install_debugpy.py",
39-
env={"PYTHONPATH": "./python_files/lib/temp"},
40-
)
41-
4235
# Download get-pip script
4336
session.run(
4437
"python",

extensions/positron-python/python_files/install_debugpy.py

-66
This file was deleted.

extensions/positron-python/python_files/tests/debug_adapter/__init__.py

-2
This file was deleted.

extensions/positron-python/python_files/tests/debug_adapter/test_install_debugpy.py

-25
This file was deleted.

extensions/positron-python/src/client/api.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ILanguageServerOutputChannel } from './activation/types';
1212
import { PythonExtension } from './api/types';
1313
import { isTestExecution, PYTHON_LANGUAGE } from './common/constants';
1414
import { IConfigurationService, Resource } from './common/types';
15-
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers';
15+
import { getDebugpyLauncherArgs } from './debugger/extension/adapter/remoteLaunchers';
1616
import { IInterpreterService } from './interpreter/contracts';
1717
import { IServiceContainer, IServiceManager } from './ioc/types';
1818
import { JupyterExtensionIntegration } from './jupyter/jupyterIntegration';
@@ -22,6 +22,7 @@ import { buildEnvironmentApi } from './environmentApi';
2222
import { ApiForPylance } from './pylanceApi';
2323
import { getTelemetryReporter } from './telemetry';
2424
import { TensorboardExtensionIntegration } from './tensorBoard/tensorboardIntegration';
25+
import { getDebugpyPath } from './debugger/pythonDebugger';
2526

2627
export function buildApi(
2728
ready: Promise<void>,
@@ -122,7 +123,7 @@ export function buildApi(
122123
});
123124
},
124125
async getDebuggerPackagePath(): Promise<string | undefined> {
125-
return getDebugpyPackagePath();
126+
return getDebugpyPath();
126127
},
127128
},
128129
settings: {

extensions/positron-python/src/client/debugger/extension/adapter/factory.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'vscode';
1616
import { EXTENSION_ROOT_DIR } from '../../../constants';
1717
import { IInterpreterService } from '../../../interpreter/contracts';
18-
import { traceLog, traceVerbose } from '../../../logging';
18+
import { traceError, traceLog, traceVerbose } from '../../../logging';
1919
import { PythonEnvironment } from '../../../pythonEnvironments/info';
2020
import { sendTelemetryEvent } from '../../../telemetry';
2121
import { EventName } from '../../../telemetry/constants';
@@ -26,6 +26,7 @@ import { Common, Interpreters } from '../../../common/utils/localize';
2626
import { IPersistentStateFactory } from '../../../common/types';
2727
import { Commands } from '../../../common/constants';
2828
import { ICommandManager } from '../../../common/application/types';
29+
import { getDebugpyPath } from '../../pythonDebugger';
2930

3031
// persistent state names, exported to make use of in testing
3132
export enum debugStateKeys {
@@ -90,15 +91,12 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
9091
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
9192
return new DebugAdapterExecutable(executable, args);
9293
}
93-
94-
const debuggerAdapterPathToUse = path.join(
95-
EXTENSION_ROOT_DIR,
96-
'python_files',
97-
'lib',
98-
'python',
99-
'debugpy',
100-
'adapter',
101-
);
94+
const debugpyPath = await getDebugpyPath();
95+
if (!debugpyPath) {
96+
traceError('Could not find debugpy path.');
97+
throw new Error('Could not find debugpy path.');
98+
}
99+
const debuggerAdapterPathToUse = path.join(debugpyPath, 'adapter');
102100

103101
const args = command.concat([debuggerAdapterPathToUse, ...logArgs]);
104102
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);

extensions/positron-python/src/client/debugger/extension/adapter/remoteLaunchers.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
'use strict';
55

6-
import * as path from 'path';
7-
import { EXTENSION_ROOT_DIR } from '../../../common/constants';
86
import '../../../common/extensions';
9-
10-
const pathToPythonLibDir = path.join(EXTENSION_ROOT_DIR, 'python_files', 'lib', 'python');
11-
const pathToDebugger = path.join(pathToPythonLibDir, 'debugpy');
7+
import { getDebugpyPath } from '../../pythonDebugger';
128

139
type RemoteDebugOptions = {
1410
host: string;
1511
port: number;
1612
waitUntilDebuggerAttaches: boolean;
1713
};
1814

19-
export function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath: string = pathToDebugger) {
15+
export async function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath?: string) {
16+
if (!debuggerPath) {
17+
debuggerPath = await getDebugpyPath();
18+
}
19+
2020
const waitArgs = options.waitUntilDebuggerAttaches ? ['--wait-for-client'] : [];
2121
return [
2222
debuggerPath.fileToCommandArgumentForPythonExt(),
@@ -25,7 +25,3 @@ export function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath
2525
...waitArgs,
2626
];
2727
}
28-
29-
export function getDebugpyPackagePath(): string {
30-
return pathToDebugger;
31-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { extensions } from 'vscode';
5+
6+
interface IPythonDebuggerExtensionApi {
7+
debug: {
8+
getDebuggerPackagePath(): Promise<string>;
9+
};
10+
}
11+
12+
async function activateExtension() {
13+
const extension = extensions.getExtension('ms-python.debugpy');
14+
if (extension) {
15+
if (!extension.isActive) {
16+
await extension.activate();
17+
}
18+
}
19+
return extension;
20+
}
21+
22+
async function getPythonDebuggerExtensionAPI(): Promise<IPythonDebuggerExtensionApi | undefined> {
23+
const extension = await activateExtension();
24+
return extension?.exports as IPythonDebuggerExtensionApi;
25+
}
26+
27+
export async function getDebugpyPath(): Promise<string> {
28+
const api = await getPythonDebuggerExtensionAPI();
29+
return api?.debug.getDebuggerPackagePath() ?? '';
30+
}

extensions/positron-python/src/client/jupyter/jupyterIntegration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type { SemVer } from 'semver';
1111
import { IContextKeyManager, IWorkspaceService } from '../common/application/types';
1212
import { JUPYTER_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../common/constants';
1313
import { GLOBAL_MEMENTO, IExtensions, IMemento, Resource } from '../common/types';
14-
import { getDebugpyPackagePath } from '../debugger/extension/adapter/remoteLaunchers';
1514
import { IEnvironmentActivationService } from '../interpreter/activation/types';
1615
import { IInterpreterQuickPickItem, IInterpreterSelector } from '../interpreter/configuration/types';
1716
import {
@@ -22,6 +21,7 @@ import {
2221
} from '../interpreter/contracts';
2322
import { PylanceApi } from '../activation/node/pylanceApi';
2423
import { ExtensionContextKey } from '../common/application/contextKeys';
24+
import { getDebugpyPath } from '../debugger/pythonDebugger';
2525
import type { Environment } from '../api/types';
2626

2727
type PythonApiForJupyterExtension = {
@@ -110,7 +110,7 @@ export class JupyterExtensionIntegration {
110110
this.interpreterSelector.getAllSuggestions(resource),
111111
getKnownSuggestions: (resource: Resource): IInterpreterQuickPickItem[] =>
112112
this.interpreterSelector.getSuggestions(resource),
113-
getDebuggerPath: async () => dirname(getDebugpyPackagePath()),
113+
getDebuggerPath: async () => dirname(await getDebugpyPath()),
114114
getInterpreterPathSelectedForJupyterServer: () =>
115115
this.globalState.get<string | undefined>('INTERPRETER_PATH_SELECTED_FOR_JUPYTER_SERVER'),
116116
registerInterpreterStatusFilter: this.interpreterDisplay.registerVisibilityFilter.bind(

extensions/positron-python/src/test/api.functional.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { assert, expect } from 'chai';
77
import * as path from 'path';
8+
import * as sinon from 'sinon';
89
import { instance, mock, when } from 'ts-mockito';
910
import { buildApi } from '../client/api';
1011
import { ConfigurationService } from '../client/common/configuration/service';
@@ -17,6 +18,7 @@ import { ServiceContainer } from '../client/ioc/container';
1718
import { ServiceManager } from '../client/ioc/serviceManager';
1819
import { IServiceContainer, IServiceManager } from '../client/ioc/types';
1920
import { IDiscoveryAPI } from '../client/pythonEnvironments/base/locator';
21+
import * as pythonDebugger from '../client/debugger/pythonDebugger';
2022

2123
suite('Extension API', () => {
2224
const debuggerPath = path.join(EXTENSION_ROOT_DIR, 'python_files', 'lib', 'python', 'debugpy');
@@ -29,6 +31,7 @@ suite('Extension API', () => {
2931
let interpreterService: IInterpreterService;
3032
let discoverAPI: IDiscoveryAPI;
3133
let environmentVariablesProvider: IEnvironmentVariablesProvider;
34+
let getDebugpyPathStub: sinon.SinonStub;
3235

3336
setup(() => {
3437
serviceContainer = mock(ServiceContainer);
@@ -47,6 +50,12 @@ suite('Extension API', () => {
4750
);
4851
when(serviceContainer.get<IInterpreterService>(IInterpreterService)).thenReturn(instance(interpreterService));
4952
when(serviceContainer.get<IDisposableRegistry>(IDisposableRegistry)).thenReturn([]);
53+
getDebugpyPathStub = sinon.stub(pythonDebugger, 'getDebugpyPath');
54+
getDebugpyPathStub.resolves(debuggerPath);
55+
});
56+
57+
teardown(() => {
58+
sinon.restore();
5059
});
5160

5261
test('Test debug launcher args (no-wait)', async () => {

0 commit comments

Comments
 (0)