Skip to content

Commit

Permalink
extension activation and context registration (#10520)
Browse files Browse the repository at this point in the history
* Extension activation and context

* update telemetry

* 💄
  • Loading branch information
rebornix authored Jun 21, 2022
1 parent 2061b60 commit 49385ce
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 120 deletions.
2 changes: 1 addition & 1 deletion TELEMETRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8335,7 +8335,7 @@ No properties for event

## Locations Used

[src/webviews/extension-side/globalActivation.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/webviews/extension-side/globalActivation.ts)
[src/webviews/extension-side/activation/globalActivation.ts](https://github.com/microsoft/vscode-jupyter/tree/main/src/webviews/extension-side/activation/globalActivation.ts)
```typescript
resultSettings[k] = currentValue;
}
Expand Down
59 changes: 1 addition & 58 deletions src/kernels/installer/productInstaller.node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable max-classes-per-file */

import { inject, injectable, named } from 'inversify';
import * as semver from 'semver';

import { CancellationTokenSource, Event, EventEmitter, Memento, Uri } from 'vscode';
import { ProductNames } from './productNames';
import {
Expand All @@ -12,7 +12,6 @@ import {
IProductService,
ModuleInstallFlags,
Product,
ProductInstallStatus,
ProductType
} from './types';
import { logValue, traceDecoratorVerbose } from '../../platform/logging';
Expand Down Expand Up @@ -112,62 +111,6 @@ abstract class BaseInstaller {
});
}

/**
*
* @param product A product which supports SemVer versioning.
* @param semVerRequirement A SemVer version requirement.
* @param resource A URI or a PythonEnvironment.
*/
public async isProductVersionCompatible(
product: Product,
semVerRequirement: string,
interpreter: PythonEnvironment
): Promise<ProductInstallStatus> {
const version = await this.getProductSemVer(product, interpreter);
if (!version) {
return ProductInstallStatus.NotInstalled;
}
if (semver.satisfies(version, semVerRequirement)) {
return ProductInstallStatus.Installed;
}
return ProductInstallStatus.NeedsUpgrade;
}

/**
*
* @param product A product which supports SemVer versioning.
* @param resource A URI or a PythonEnvironment.
*/
private async getProductSemVer(product: Product, interpreter: PythonEnvironment): Promise<semver.SemVer | null> {
const executableName = this.getExecutableNameFromSettings(product, undefined);
const isModule = this.isExecutableAModule(product, undefined);

let version;
if (isModule) {
const pythonProcess = await this.serviceContainer
.get<IPythonExecutionFactory>(IPythonExecutionFactory)
.createActivatedEnvironment({ interpreter, allowEnvironmentFetchExceptions: true });
const args = ['-c', `import ${executableName}; print(${executableName}.__version__)`];
const result = await pythonProcess.exec(args, { mergeStdOutErr: true });
version = result.stdout.trim();
} else {
const process = await this.serviceContainer
.get<IProcessServiceFactory>(IProcessServiceFactory)
.create(undefined);
const result = await process.exec(executableName, ['--version'], { mergeStdOutErr: true });
version = result.stdout.trim();
}
if (!version) {
return null;
}
try {
return semver.coerce(version);
} catch (e) {
traceError(`Unable to parse version ${version} for product ${product}: `, e);
return null;
}
}

@traceDecoratorVerbose('Checking if product is installed')
public async isInstalled(product: Product, @logValue('path') interpreter: PythonEnvironment): Promise<boolean> {
const executableName = this.getExecutableNameFromSettings(product, undefined);
Expand Down
14 changes: 0 additions & 14 deletions src/platform/activation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ export interface IExtensionActivationManager extends IDisposable {
activate(): Promise<void>;
}

export const IDownloadChannelRule = Symbol('IDownloadChannelRule');
export enum PlatformName {
Windows32Bit = 'win-x86',
Windows64Bit = 'win-x64',
Mac64Bit = 'osx-x64',
Linux64Bit = 'linux-x64'
}
export const IPlatformData = Symbol('IPlatformData');
export interface IPlatformData {
readonly platformName: PlatformName;
readonly engineDllName: string;
readonly engineExecutableName: string;
}

export const IExtensionSingleActivationService = Symbol('IExtensionSingleActivationService');
/**
* Classes implementing this interface will have their `activate` methods
Expand Down
2 changes: 1 addition & 1 deletion src/test/datascience/datascience.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { WorkspaceService } from '../../platform/common/application/workspace.no
import { JupyterSettings } from '../../platform/common/configSettings';
import { ConfigurationService } from '../../platform/common/configuration/service.node';
import { IConfigurationService, IWatchableJupyterSettings } from '../../platform/common/types';
import { GlobalActivation } from '../../webviews/extension-side/globalActivation';
import { GlobalActivation } from '../../webviews/extension-side/activation/globalActivation';
import { DataScienceCodeLensProvider } from '../../interactive-window/editor-integration/codelensprovider';
import { RawNotebookSupportedService } from '../../kernels/raw/session/rawNotebookSupportedService.node';
import { IDataScienceCodeLensProvider } from '../../interactive-window/editor-integration/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IExtensionActivationManager,
IExtensionSingleActivationService,
IExtensionSyncActivationService
} from '../../platform/activation/types';
} from '../../../platform/activation/types';

@injectable()
export class ExtensionActivationManager implements IExtensionActivationManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
import type { JSONObject } from '@lumino/coreutils';
import { inject, injectable, multiInject, optional } from 'inversify';
import * as vscode from 'vscode';
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../platform/common/application/types';
import { PYTHON_FILE_ANY_SCHEME, PYTHON_LANGUAGE } from '../../platform/common/constants';
import { ContextKey } from '../../platform/common/contextKey';
import '../../platform/common/extensions';
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../../../platform/common/application/types';
import { PYTHON_FILE_ANY_SCHEME, PYTHON_LANGUAGE } from '../../../platform/common/constants';
import { ContextKey } from '../../../platform/common/contextKey';
import '../../../platform/common/extensions';
import {
IConfigurationService,
IDataScienceCommandListener,
IDisposable,
IDisposableRegistry,
IExtensionContext
} from '../../platform/common/types';
import { debounceAsync, swallowExceptions } from '../../platform/common/utils/decorators';
import { noop } from '../../platform/common/utils/misc';
import { sendTelemetryEvent } from '../../telemetry';
import { EditorContexts, Telemetry } from '../../platform/common/constants';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { IDataScienceCodeLensProvider } from '../../interactive-window/editor-integration/types';
import { IRawNotebookSupportedService } from '../../kernels/raw/types';
import { hasCells } from '../../interactive-window/editor-integration/cellFactory';
} from '../../../platform/common/types';
import { debounceAsync, swallowExceptions } from '../../../platform/common/utils/decorators';
import { noop } from '../../../platform/common/utils/misc';
import { sendTelemetryEvent } from '../../../telemetry';
import { EditorContexts, Telemetry } from '../../../platform/common/constants';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { IDataScienceCodeLensProvider } from '../../../interactive-window/editor-integration/types';
import { IRawNotebookSupportedService } from '../../../kernels/raw/types';
import { hasCells } from '../../../interactive-window/editor-integration/cellFactory';

@injectable()
export class GlobalActivation implements IExtensionSingleActivationService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { inject, injectable } from 'inversify';
import { TextDocument } from 'vscode';
import { sendActivationTelemetry } from '../../telemetry/envFileTelemetry.node';
import { IPythonExtensionChecker } from '../../platform/api/types';
import { IWorkspaceService, IActiveResourceService, IDocumentManager } from '../../platform/common/application/types';
import { PYTHON_LANGUAGE } from '../../platform/common/constants';
import { IFileSystemNode } from '../../platform/common/platform/types.node';
import { IDisposable, Resource } from '../../platform/common/types';
import { Deferred } from '../../platform/common/utils/async';
import { IInterpreterService } from '../../platform/interpreter/contracts';
import { traceDecoratorError } from '../../platform/logging';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { sendActivationTelemetry } from '../../../telemetry/envFileTelemetry.node';
import { IPythonExtensionChecker } from '../../../platform/api/types';
import {
IWorkspaceService,
IActiveResourceService,
IDocumentManager
} from '../../../platform/common/application/types';
import { PYTHON_LANGUAGE } from '../../../platform/common/constants';
import { IFileSystemNode } from '../../../platform/common/platform/types.node';
import { IDisposable, Resource } from '../../../platform/common/types';
import { Deferred } from '../../../platform/common/utils/async';
import { IInterpreterService } from '../../../platform/interpreter/contracts';
import { traceDecoratorError } from '../../../platform/logging';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';

@injectable()
export class WorkspaceActivation implements IExtensionSingleActivationService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
'use strict';
import { inject, injectable, optional } from 'inversify';
import { NotebookEditor, TextEditor } from 'vscode';
import { IKernel, IKernelProvider } from '../../kernels/types';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { ICommandManager, IDocumentManager, IVSCodeNotebook } from '../../platform/common/application/types';
import { EditorContexts, PYTHON_LANGUAGE } from '../../platform/common/constants';
import { ContextKey } from '../../platform/common/contextKey';
import { IDisposable, IDisposableRegistry } from '../../platform/common/types';
import { isNotebookCell, noop } from '../../platform/common/utils/misc';
import { InteractiveWindowView, JupyterNotebookView } from '../../platform/common/constants';
import { INotebookControllerManager } from '../../notebooks/types';
import { IInteractiveWindowProvider, IInteractiveWindow } from '../../interactive-window/types';
import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from '../../platform/common/utils';
import { getAssociatedNotebookDocument } from '../../kernels/helpers';
import { IKernel, IKernelProvider } from '../../../kernels/types';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { ICommandManager, IDocumentManager, IVSCodeNotebook } from '../../../platform/common/application/types';
import { EditorContexts, PYTHON_LANGUAGE } from '../../../platform/common/constants';
import { ContextKey } from '../../../platform/common/contextKey';
import { IDisposable, IDisposableRegistry } from '../../../platform/common/types';
import { isNotebookCell, noop } from '../../../platform/common/utils/misc';
import { InteractiveWindowView, JupyterNotebookView } from '../../../platform/common/constants';
import { INotebookControllerManager } from '../../../notebooks/types';
import { IInteractiveWindowProvider, IInteractiveWindow } from '../../../interactive-window/types';
import { getNotebookMetadata, isJupyterNotebook, isPythonNotebook } from '../../../platform/common/utils';
import { getAssociatedNotebookDocument } from '../../../kernels/helpers';

@injectable()
export class ActiveEditorContextService implements IExtensionSingleActivationService, IDisposable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { injectable } from 'inversify';
import { env } from 'vscode';
import { IExtensionSingleActivationService } from '../../platform/activation/types';
import { setSharedProperty } from '../../telemetry';
import { IExtensionSingleActivationService } from '../../../platform/activation/types';
import { setSharedProperty } from '../../../telemetry';

const amlComputeRemoteName = 'amlext';

Expand Down
10 changes: 5 additions & 5 deletions src/webviews/extension-side/serviceRegistry.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ import { DataViewerFactory } from './dataviewer/dataViewerFactory';
import { NotebookWatcher } from './variablesView/notebookWatcher';
import { ExtensionSideRenderer, IExtensionSideRenderer } from './renderer';
import { ExtensionRecommendationService } from './extensionRecommendation.node';
import { ActiveEditorContextService } from './activeEditorContext';
import { AmlComputeContext } from './amlContext.node';
import { ActiveEditorContextService } from './context/activeEditorContext';
import { AmlComputeContext } from './context/amlContext.node';
import { IImportTracker, ImportTracker } from './importTracker.node';
import { GlobalActivation } from './globalActivation';
import { GlobalActivation } from './activation/globalActivation';
import { JupyterKernelServiceFactory } from './api/kernelApi';
import { IExportedKernelServiceFactory } from './api/api';
import { ApiAccessService } from './api/apiAccessService';
import { WorkspaceActivation } from './workspaceActivation.node';
import { ExtensionActivationManager } from './activationManager';
import { WorkspaceActivation } from './activation/workspaceActivation.node';
import { ExtensionActivationManager } from './activation/activationManager';
import { DataScienceSurveyBanner, ISurveyBanner } from './survey/dataScienceSurveyBanner.node';

export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) {
Expand Down
6 changes: 3 additions & 3 deletions src/webviews/extension-side/serviceRegistry.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import { CommandRegistry as ExportCommandRegistry } from './import-export/comman
import { NotebookWatcher } from './variablesView/notebookWatcher';
import { DataViewerFactory } from './dataviewer/dataViewerFactory';
import { ExtensionSideRenderer, IExtensionSideRenderer } from './renderer';
import { ActiveEditorContextService } from './activeEditorContext';
import { GlobalActivation } from './globalActivation';
import { ActiveEditorContextService } from './context/activeEditorContext';
import { GlobalActivation } from './activation/globalActivation';
import { DataViewer } from './dataviewer/dataViewer';
import { INotebookExporter } from '../../kernels/jupyter/types';
import { JupyterExporter } from './import-export/jupyterExporter';
import { JupyterKernelServiceFactory } from './api/kernelApi';
import { IExportedKernelServiceFactory } from './api/api';
import { ApiAccessService } from './api/apiAccessService';
import { ExtensionActivationManager } from './activationManager';
import { ExtensionActivationManager } from './activation/activationManager';

export function registerTypes(serviceManager: IServiceManager, _isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSingleActivationService>(IExtensionSingleActivationService, GlobalActivation);
Expand Down

0 comments on commit 49385ce

Please sign in to comment.