Skip to content

Use python debugger api #23211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 16, 2024
Merged
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ contact_links:
- name: 'Jupyter'
url: https://github.com/microsoft/vscode-jupyter/issues
about: 'For issues relating to the Jupyter extension (including the interactive window)'
- name: 'Debugpy'
url: https://github.com/microsoft/debugpy/issues
about: 'For issues relating to the debugpy debugger'
- name: 'Python Debugger'
url: https://github.com/microsoft/vscode-python-debugger/issues
about: 'For issues relating to the Python debugger'
- name: Help/Support
url: https://github.com/microsoft/vscode-python/discussions/categories/q-a
about: 'Having trouble with the extension? Need help getting something to work?'
2 changes: 1 addition & 1 deletion .github/actions/build-vsix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runs:
run: python -m pip install wheel nox
shell: bash

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

Expand Down
1 change: 0 additions & 1 deletion .github/actions/smoke-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ runs:
- name: pip install system test requirements
run: |
python -m pip install --upgrade -r build/test-requirements.txt
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --implementation py --no-deps --upgrade --pre debugpy
shell: bash

# Bits from the VSIX are reused by smokeTest.ts to speed things up.
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ jobs:

- name: Install other Python requirements
run: |
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
python -m pip install --upgrade -r build/test-requirements.txt

- name: Run Pyright
Expand Down Expand Up @@ -195,7 +194,7 @@ jobs:
- name: Install build pre-requisite
run: python -m pip install wheel nox

- name: Install Python Extension dependencies (jedi, debugpy, etc.)
- name: Install Python Extension dependencies (jedi, etc.)
run: nox --session install_python_libs

- name: Install test requirements
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jobs:

- name: Install other Python requirements
run: |
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy
python -m pip install --upgrade -r build/test-requirements.txt

- name: Run Pyright
Expand Down Expand Up @@ -183,7 +182,7 @@ jobs:
- name: Install build pre-requisite
run: python -m pip install wheel nox

- name: Install Python Extension dependencies (jedi, debugpy, etc.)
- name: Install Python Extension dependencies (jedi, etc.)
run: nox --session install_python_libs

- name: Install test requirements
Expand Down Expand Up @@ -386,11 +385,6 @@ jobs:
requirements-file: './python_files/jedilsp_requirements/requirements.txt'
options: '-t ./python_files/lib/jedilsp --implementation py'

- name: Install debugpy
run: |
# 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.
python -m pip --disable-pip-version-check install -t ./python_files/lib/python --implementation py --no-deps --upgrade --pre debugpy

- name: Install test requirements
run: python -m pip install --upgrade -r build/test-requirements.txt

Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipeline.pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extends:

- script: |
nox --session install_python_libs
displayName: Install debugpy, Jedi, get-pip, etc
displayName: Install Jedi, get-pip, etc

- script: |
python ./build/update_ext_version.py --for-publishing
Expand Down
2 changes: 1 addition & 1 deletion build/azure-pipeline.stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extends:

- script: |
nox --session install_python_libs
displayName: Install debugpy, Jedi, get-pip, etc
displayName: Install Jedi, get-pip, etc

- script: |
python ./build/update_ext_version.py --release --for-publishing
Expand Down
7 changes: 0 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def install_python_libs(session: nox.Session):

session.install("packaging")

# Install debugger
session.run(
"python",
"./python_files/install_debugpy.py",
env={"PYTHONPATH": "./python_files/lib/temp"},
)

# Download get-pip script
session.run(
"python",
Expand Down
66 changes: 0 additions & 66 deletions python_files/install_debugpy.py

This file was deleted.

2 changes: 0 additions & 2 deletions python_files/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ extraPaths = ['lib/python', 'lib/jedilsp']
ignore = [
# Ignore all pre-existing code with issues
'get-pip.py',
'install_debugpy.py',
'tensorboard_launcher.py',
'testlauncher.py',
'visualstudio_py_testlauncher.py',
'testing_tools/unittest_discovery.py',
'testing_tools/adapter/util.py',
'testing_tools/adapter/pytest/_discovery.py',
'testing_tools/adapter/pytest/_pytest_item.py',
'tests/debug_adapter/test_install_debugpy.py',
'tests/testing_tools/adapter/.data',
'tests/testing_tools/adapter/test___main__.py',
'tests/testing_tools/adapter/test_discovery.py',
Expand Down
2 changes: 0 additions & 2 deletions python_files/tests/debug_adapter/__init__.py

This file was deleted.

25 changes: 0 additions & 25 deletions python_files/tests/debug_adapter/test_install_debugpy.py

This file was deleted.

5 changes: 3 additions & 2 deletions src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ILanguageServerOutputChannel } from './activation/types';
import { PythonExtension } from './api/types';
import { isTestExecution, PYTHON_LANGUAGE } from './common/constants';
import { IConfigurationService, Resource } from './common/types';
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers';
import { getDebugpyLauncherArgs } from './debugger/extension/adapter/remoteLaunchers';
import { IInterpreterService } from './interpreter/contracts';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { JupyterExtensionIntegration } from './jupyter/jupyterIntegration';
Expand All @@ -22,6 +22,7 @@ import { buildEnvironmentApi } from './environmentApi';
import { ApiForPylance } from './pylanceApi';
import { getTelemetryReporter } from './telemetry';
import { TensorboardExtensionIntegration } from './tensorBoard/tensorboardIntegration';
import { getDebugpyPath } from './debugger/pythonDebugger';

export function buildApi(
ready: Promise<void>,
Expand Down Expand Up @@ -122,7 +123,7 @@ export function buildApi(
});
},
async getDebuggerPackagePath(): Promise<string | undefined> {
return getDebugpyPackagePath();
return getDebugpyPath();
},
},
settings: {
Expand Down
18 changes: 8 additions & 10 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 {
} from 'vscode';
import { EXTENSION_ROOT_DIR } from '../../../constants';
import { IInterpreterService } from '../../../interpreter/contracts';
import { traceLog, traceVerbose } from '../../../logging';
import { traceError, traceLog, traceVerbose } from '../../../logging';
import { PythonEnvironment } from '../../../pythonEnvironments/info';
import { sendTelemetryEvent } from '../../../telemetry';
import { EventName } from '../../../telemetry/constants';
Expand All @@ -26,6 +26,7 @@ import { Common, Interpreters } from '../../../common/utils/localize';
import { IPersistentStateFactory } from '../../../common/types';
import { Commands } from '../../../common/constants';
import { ICommandManager } from '../../../common/application/types';
import { getDebugpyPath } from '../../pythonDebugger';

// persistent state names, exported to make use of in testing
export enum debugStateKeys {
Expand Down Expand Up @@ -90,15 +91,12 @@ export class DebugAdapterDescriptorFactory implements IDebugAdapterDescriptorFac
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
return new DebugAdapterExecutable(executable, args);
}

const debuggerAdapterPathToUse = path.join(
EXTENSION_ROOT_DIR,
'python_files',
'lib',
'python',
'debugpy',
'adapter',
);
const debugpyPath = await getDebugpyPath();
if (!debugpyPath) {
traceError('Could not find debugpy path.');
throw new Error('Could not find debugpy path.');
}
const debuggerAdapterPathToUse = path.join(debugpyPath, 'adapter');

const args = command.concat([debuggerAdapterPathToUse, ...logArgs]);
traceLog(`DAP Server launched with command: ${executable} ${args.join(' ')}`);
Expand Down
16 changes: 6 additions & 10 deletions src/client/debugger/extension/adapter/remoteLaunchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

'use strict';

import * as path from 'path';
import { EXTENSION_ROOT_DIR } from '../../../common/constants';
import '../../../common/extensions';

const pathToPythonLibDir = path.join(EXTENSION_ROOT_DIR, 'python_files', 'lib', 'python');
const pathToDebugger = path.join(pathToPythonLibDir, 'debugpy');
import { getDebugpyPath } from '../../pythonDebugger';

type RemoteDebugOptions = {
host: string;
port: number;
waitUntilDebuggerAttaches: boolean;
};

export function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath: string = pathToDebugger) {
export async function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath?: string) {
if (!debuggerPath) {
debuggerPath = await getDebugpyPath();
}

const waitArgs = options.waitUntilDebuggerAttaches ? ['--wait-for-client'] : [];
return [
debuggerPath.fileToCommandArgumentForPythonExt(),
Expand All @@ -25,7 +25,3 @@ export function getDebugpyLauncherArgs(options: RemoteDebugOptions, debuggerPath
...waitArgs,
];
}

export function getDebugpyPackagePath(): string {
return pathToDebugger;
}
30 changes: 30 additions & 0 deletions src/client/debugger/pythonDebugger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { extensions } from 'vscode';

interface IPythonDebuggerExtensionApi {
debug: {
getDebuggerPackagePath(): Promise<string>;
};
}

async function activateExtension() {
const extension = extensions.getExtension('ms-python.debugpy');
if (extension) {
if (!extension.isActive) {
await extension.activate();
}
}
return extension;
}

async function getPythonDebuggerExtensionAPI(): Promise<IPythonDebuggerExtensionApi | undefined> {
const extension = await activateExtension();
return extension?.exports as IPythonDebuggerExtensionApi;
}

export async function getDebugpyPath(): Promise<string> {
const api = await getPythonDebuggerExtensionAPI();
return api?.debug.getDebuggerPackagePath() ?? '';
}
4 changes: 2 additions & 2 deletions src/client/jupyter/jupyterIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { SemVer } from 'semver';
import { IContextKeyManager, IWorkspaceService } from '../common/application/types';
import { JUPYTER_EXTENSION_ID, PYLANCE_EXTENSION_ID } from '../common/constants';
import { GLOBAL_MEMENTO, IExtensions, IMemento, Resource } from '../common/types';
import { getDebugpyPackagePath } from '../debugger/extension/adapter/remoteLaunchers';
import { IEnvironmentActivationService } from '../interpreter/activation/types';
import { IInterpreterQuickPickItem, IInterpreterSelector } from '../interpreter/configuration/types';
import {
Expand All @@ -22,6 +21,7 @@ import {
} from '../interpreter/contracts';
import { PylanceApi } from '../activation/node/pylanceApi';
import { ExtensionContextKey } from '../common/application/contextKeys';
import { getDebugpyPath } from '../debugger/pythonDebugger';
import type { Environment } from '../api/types';

type PythonApiForJupyterExtension = {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class JupyterExtensionIntegration {
this.interpreterSelector.getAllSuggestions(resource),
getKnownSuggestions: (resource: Resource): IInterpreterQuickPickItem[] =>
this.interpreterSelector.getSuggestions(resource),
getDebuggerPath: async () => dirname(getDebugpyPackagePath()),
getDebuggerPath: async () => dirname(await getDebugpyPath()),
getInterpreterPathSelectedForJupyterServer: () =>
this.globalState.get<string | undefined>('INTERPRETER_PATH_SELECTED_FOR_JUPYTER_SERVER'),
registerInterpreterStatusFilter: this.interpreterDisplay.registerVisibilityFilter.bind(
Expand Down
Loading
Loading