From 439f11b6db7daa819056007fdc507330790bdb3a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 17 Sep 2020 09:39:13 -0700 Subject: [PATCH 1/4] Debugger API for DS --- .../datascience/api/jupyterIntegration.ts | 57 +++++++++++-------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/client/datascience/api/jupyterIntegration.ts b/src/client/datascience/api/jupyterIntegration.ts index 4df5a8a7cd11..c4b55e896eee 100644 --- a/src/client/datascience/api/jupyterIntegration.ts +++ b/src/client/datascience/api/jupyterIntegration.ts @@ -6,9 +6,11 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; +import { join } from 'path'; import { CancellationToken, Event, Uri } from 'vscode'; import { InterpreterUri } from '../../common/installer/types'; import { IExtensions, IInstaller, InstallerResponse, Product, Resource } from '../../common/types'; +import { EXTENSION_ROOT_DIR } from '../../constants'; import { IEnvironmentActivationService } from '../../interpreter/activation/types'; import { IInterpreterQuickPickItem, IInterpreterSelector } from '../../interpreter/configuration/types'; import { IInterpreterService } from '../../interpreter/contracts'; @@ -51,6 +53,10 @@ type PythonApiForJupyterExtension = { * IInstaller */ install(product: Product, resource?: InterpreterUri, cancel?: CancellationToken): Promise; + /** + * Returns path to where `debugpy` is. In python extension this is `/pythonFiles/lib/python`. + */ + getDebuggerPath(): Promise; }; type JupyterExtensionApi = { @@ -73,31 +79,34 @@ export class JupyterExtensionIntegration { if (!jupyterExtension) { return; } - await jupyterExtension.activate(); if (!jupyterExtension.isActive) { - return; + await jupyterExtension.activate(); + } + await jupyterExtension.activate(); + if (jupyterExtension.isActive) { + const jupyterExtensionApi = jupyterExtension.exports; + jupyterExtensionApi.registerPythonApi({ + onDidChangeInterpreter: this.interpreterService.onDidChangeInterpreter, + getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource), + getInterpreterDetails: async (pythonPath: string) => + this.interpreterService.getInterpreterDetails(pythonPath), + getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getInterpreters(resource), + getActivatedEnvironmentVariables: async ( + resource: Resource, + interpreter?: PythonEnvironment, + allowExceptions?: boolean + ) => this.envActivation.getActivatedEnvironmentVariables(resource, interpreter, allowExceptions), + isWindowsStoreInterpreter: async (pythonPath: string): Promise => + this.windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath), + getSuggestions: async (resource: Resource): Promise => + this.interpreterSelector.getSuggestions(resource), + install: async ( + product: Product, + resource?: InterpreterUri, + cancel?: CancellationToken + ): Promise => this.installer.install(product, resource, cancel), + getDebuggerPath: async () => join(EXTENSION_ROOT_DIR, 'pythonFiles', 'lib', 'python') + }); } - const jupyterExtensionApi = jupyterExtension.exports; - jupyterExtensionApi.registerPythonApi({ - onDidChangeInterpreter: this.interpreterService.onDidChangeInterpreter, - getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource), - getInterpreterDetails: async (pythonPath: string) => - this.interpreterService.getInterpreterDetails(pythonPath), - getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getInterpreters(resource), - getActivatedEnvironmentVariables: async ( - resource: Resource, - interpreter?: PythonEnvironment, - allowExceptions?: boolean - ) => this.envActivation.getActivatedEnvironmentVariables(resource, interpreter, allowExceptions), - isWindowsStoreInterpreter: async (pythonPath: string): Promise => - this.windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath), - getSuggestions: async (resource: Resource): Promise => - this.interpreterSelector.getSuggestions(resource), - install: async ( - product: Product, - resource?: InterpreterUri, - cancel?: CancellationToken - ): Promise => this.installer.install(product, resource, cancel) - }); } } From 374f3299018fcbcefc6dc4dc03036d531e282edd Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 17 Sep 2020 09:40:48 -0700 Subject: [PATCH 2/4] Oops --- src/client/datascience/api/jupyterIntegration.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/datascience/api/jupyterIntegration.ts b/src/client/datascience/api/jupyterIntegration.ts index c4b55e896eee..fd0e895c46e1 100644 --- a/src/client/datascience/api/jupyterIntegration.ts +++ b/src/client/datascience/api/jupyterIntegration.ts @@ -79,10 +79,10 @@ export class JupyterExtensionIntegration { if (!jupyterExtension) { return; } + await jupyterExtension.activate(); if (!jupyterExtension.isActive) { - await jupyterExtension.activate(); + return; } - await jupyterExtension.activate(); if (jupyterExtension.isActive) { const jupyterExtensionApi = jupyterExtension.exports; jupyterExtensionApi.registerPythonApi({ From fa136f41feb664a40f21a94e65f260e0b56652ba Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 17 Sep 2020 09:42:25 -0700 Subject: [PATCH 3/4] OOps --- .../datascience/api/jupyterIntegration.ts | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/client/datascience/api/jupyterIntegration.ts b/src/client/datascience/api/jupyterIntegration.ts index fd0e895c46e1..903dc0349d46 100644 --- a/src/client/datascience/api/jupyterIntegration.ts +++ b/src/client/datascience/api/jupyterIntegration.ts @@ -83,30 +83,28 @@ export class JupyterExtensionIntegration { if (!jupyterExtension.isActive) { return; } - if (jupyterExtension.isActive) { - const jupyterExtensionApi = jupyterExtension.exports; - jupyterExtensionApi.registerPythonApi({ - onDidChangeInterpreter: this.interpreterService.onDidChangeInterpreter, - getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource), - getInterpreterDetails: async (pythonPath: string) => - this.interpreterService.getInterpreterDetails(pythonPath), - getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getInterpreters(resource), - getActivatedEnvironmentVariables: async ( - resource: Resource, - interpreter?: PythonEnvironment, - allowExceptions?: boolean - ) => this.envActivation.getActivatedEnvironmentVariables(resource, interpreter, allowExceptions), - isWindowsStoreInterpreter: async (pythonPath: string): Promise => - this.windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath), - getSuggestions: async (resource: Resource): Promise => - this.interpreterSelector.getSuggestions(resource), - install: async ( - product: Product, - resource?: InterpreterUri, - cancel?: CancellationToken - ): Promise => this.installer.install(product, resource, cancel), - getDebuggerPath: async () => join(EXTENSION_ROOT_DIR, 'pythonFiles', 'lib', 'python') - }); - } + const jupyterExtensionApi = jupyterExtension.exports; + jupyterExtensionApi.registerPythonApi({ + onDidChangeInterpreter: this.interpreterService.onDidChangeInterpreter, + getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource), + getInterpreterDetails: async (pythonPath: string) => + this.interpreterService.getInterpreterDetails(pythonPath), + getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getInterpreters(resource), + getActivatedEnvironmentVariables: async ( + resource: Resource, + interpreter?: PythonEnvironment, + allowExceptions?: boolean + ) => this.envActivation.getActivatedEnvironmentVariables(resource, interpreter, allowExceptions), + isWindowsStoreInterpreter: async (pythonPath: string): Promise => + this.windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath), + getSuggestions: async (resource: Resource): Promise => + this.interpreterSelector.getSuggestions(resource), + install: async ( + product: Product, + resource?: InterpreterUri, + cancel?: CancellationToken + ): Promise => this.installer.install(product, resource, cancel), + getDebuggerPath: async () => join(EXTENSION_ROOT_DIR, 'pythonFiles', 'lib', 'python') + }); } } From d34c91b2e1b7d1d459b33704d9aa62cf85957206 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 17 Sep 2020 11:57:00 -0700 Subject: [PATCH 4/4] Code review changes --- src/client/datascience/api/jupyterIntegration.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/datascience/api/jupyterIntegration.ts b/src/client/datascience/api/jupyterIntegration.ts index 903dc0349d46..36bb40d93ff0 100644 --- a/src/client/datascience/api/jupyterIntegration.ts +++ b/src/client/datascience/api/jupyterIntegration.ts @@ -6,11 +6,11 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; -import { join } from 'path'; +import { dirname } from 'path'; import { CancellationToken, Event, Uri } from 'vscode'; import { InterpreterUri } from '../../common/installer/types'; import { IExtensions, IInstaller, InstallerResponse, Product, Resource } from '../../common/types'; -import { EXTENSION_ROOT_DIR } from '../../constants'; +import { getDebugpyPackagePath } from '../../debugger/extension/adapter/remoteLaunchers'; import { IEnvironmentActivationService } from '../../interpreter/activation/types'; import { IInterpreterQuickPickItem, IInterpreterSelector } from '../../interpreter/configuration/types'; import { IInterpreterService } from '../../interpreter/contracts'; @@ -104,7 +104,7 @@ export class JupyterExtensionIntegration { resource?: InterpreterUri, cancel?: CancellationToken ): Promise => this.installer.install(product, resource, cancel), - getDebuggerPath: async () => join(EXTENSION_ROOT_DIR, 'pythonFiles', 'lib', 'python') + getDebuggerPath: async () => dirname(getDebugpyPackagePath()) }); } }