Skip to content

Commit

Permalink
Merge pull request #1 from vscode-python-datascience/dev/ianhu/DataSc…
Browse files Browse the repository at this point in the history
…ienceChanges

merge in changes from the old data science branch
  • Loading branch information
IanMatthewHuff authored Sep 26, 2018
2 parents b078e4c + 640c2e6 commit b81aa44
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@
"command": "python.runLinting",
"title": "%python.command.python.runLinting.title%",
"category": "Python"
},
{
"command": "python.datascience",
"title": "%python.command.python.datascience.datascience.title%",
"category": "Python"
}
],
"menus": {
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"python.command.python.setLinter.title": "Select Linter",
"python.command.python.enableLinting.title": "Enable Linting",
"python.command.python.runLinting.title": "Run Linting",
"python.command.python.datascience.datascience.title": "Data Science Test Command",
"python.snippet.launch.standard.label": "Python: Current File",
"python.snippet.launch.standard.description": "Debug a Python Program with Standard Output",
"python.snippet.launch.pyspark.label": "Python: PySpark",
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/codewatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
8 changes: 8 additions & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

export namespace Commands {
export const DataScience = 'python.datascience';
}
37 changes: 37 additions & 0 deletions src/client/datascience/datascience.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject, injectable } from 'inversify';
import { IApplicationShell, ICommandManager } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { IServiceContainer } from '../ioc/types';
import { Commands } from './constants';
import { IDataScience } from './types';

@injectable()
export class DataScience implements IDataScience {
private readonly appShell: IApplicationShell;
private readonly commandManager: ICommandManager;
private readonly disposableRegistry: IDisposableRegistry;
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer)
{
this.appShell = this.serviceContainer.get<IApplicationShell>(IApplicationShell);
this.commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager);
this.disposableRegistry = this.serviceContainer.get<IDisposableRegistry>(IDisposableRegistry);
}

public async activate(): Promise<void> {
this.registerCommands();
}

public async executeDataScience(): Promise<void> {
await this.appShell.showInformationMessage('Hello Data Science');
}

private registerCommands(): void {
const disposable = this.commandManager.registerCommand(Commands.DataScience, this.executeDataScience, this);
this.disposableRegistry.push(disposable);
}
}
4 changes: 4 additions & 0 deletions src/client/datascience/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
4 changes: 4 additions & 0 deletions src/client/datascience/historypostoffice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
16 changes: 16 additions & 0 deletions src/client/datascience/jupyterserverprovider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { injectable } from 'inversify';
import { IJupyterServer, IJupyterServerProvider } from './types';

@injectable()
export class JupyterServerProvider implements IJupyterServerProvider {
public start(notebookFile: string | undefined): Promise<IJupyterServer> {
return new Promise<IJupyterServer>((resolve, reject) => {
resolve(undefined);
});
}
}
14 changes: 14 additions & 0 deletions src/client/datascience/serviceRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { IServiceManager } from '../ioc/types';
import { DataScience } from './datascience';
import { JupyterServerProvider } from './jupyterserverprovider';
import { IDataScience, IJupyterServerProvider } from './types';

export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IDataScience>(IDataScience, DataScience);
serviceManager.addSingleton<IJupyterServerProvider>(IJupyterServerProvider, JupyterServerProvider);
}
49 changes: 49 additions & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

// Main interface
export const IDataScience = Symbol('IDataScience');
export interface IDataScience {
activate(): Promise<void>;
executeDataScience(): Promise<void>;
}

// Factory for jupyter servers
export const IJupyterServerProvider = Symbol('IJupyterServerFactory');
export interface IJupyterServerProvider {
start(notebookFile: string | undefined): Promise<IJupyterServer>;
}

// Talks to a jupyter kernel to retrieve data for cells
export const IJupyterServer = Symbol('IJupyterServer');
export interface IJupyterServer {
}

// Wraps the VS Code api for creating a web panel
export const IWebPanelProvider = Symbol('IWebPanelProvider');
export interface IWebPanelProvider {
create(): IWebPanel;
}

// Wraps the VS Code webview panel
export const IWebPanel = Symbol('IWebPanel');
export interface IWebPanel {
}

// Wraps the vscode API in order to send messages back and forth from a webview
export const IPostOffice = Symbol('IPostOffice');
export interface IPostOffice {
// tslint:disable-next-line:no-any
post(message: string, params: any[] | undefined);
// tslint:disable-next-line:no-any
listen(message: string, listener: (args: any[] | undefined) => void);
}

// Basic structure for a cell from a notebook
export interface ICell {
input: string;
output: string;
id: number;
}
7 changes: 7 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
IMemento, IOutputChannel, WORKSPACE_MEMENTO
} from './common/types';
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
import { registerTypes as dataScienceRegisterTypes } from './datascience/serviceRegistry';
import { IDataScience } from './datascience/types';
import { AttachRequestArguments, LaunchRequestArguments } from './debugger/Common/Contracts';
import { BaseConfigurationProvider } from './debugger/configProviders/baseProvider';
import { registerTypes as debugConfigurationRegisterTypes } from './debugger/configProviders/serviceRegistry';
Expand Down Expand Up @@ -105,6 +107,10 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
const lintingEngine = serviceManager.get<ILintingEngine>(ILintingEngine);
lintingEngine.linkJupiterExtension(jupyterExtension).ignoreErrors();

// Activate data science features
const dataScience = serviceManager.get<IDataScience>(IDataScience);
dataScience.activate().ignoreErrors();

context.subscriptions.push(new LinterCommands(serviceManager));
const linterProvider = new LinterProvider(context, serviceManager);
context.subscriptions.push(linterProvider);
Expand Down Expand Up @@ -185,6 +191,7 @@ function registerServices(context: ExtensionContext, serviceManager: ServiceMana
platformRegisterTypes(serviceManager);
installerRegisterTypes(serviceManager);
commonRegisterTerminalTypes(serviceManager);
dataScienceRegisterTypes(serviceManager);
debugConfigurationRegisterTypes(serviceManager);
debuggerRegisterTypes(serviceManager);
appRegisterTypes(serviceManager);
Expand Down
46 changes: 46 additions & 0 deletions src/test/datascience/datascience.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import * as TypeMoq from 'typemoq';
import { IApplicationShell, ICommandManager } from '../../client/common/application/types';
import { IDisposableRegistry } from '../../client/common/types';
import { Commands } from '../../client/datascience/constants';
import { DataScience } from '../../client/datascience/datascience';
import { IDataScience } from '../../client/datascience/types';
import { IServiceContainer } from '../../client/ioc/types';

suite('Data Science Tests', () => {
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let shell: TypeMoq.IMock<IApplicationShell>;
let commandManager: TypeMoq.IMock<ICommandManager>;
let disposableRegistry: TypeMoq.IMock<IDisposableRegistry>;
let dataScience: IDataScience;
setup(() => {
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
commandManager = TypeMoq.Mock.ofType<ICommandManager>();
disposableRegistry = TypeMoq.Mock.ofType<IDisposableRegistry>();
shell = TypeMoq.Mock.ofType<IApplicationShell>();
serviceContainer.setup(c => c.get(ICommandManager)).returns(() => commandManager.object);
serviceContainer.setup(c => c.get(IApplicationShell)).returns(() => shell.object);
serviceContainer.setup(c => c.get(IDisposableRegistry)).returns(() => disposableRegistry.object);

dataScience = new DataScience(serviceContainer.object);
});
test('Ensure command is registered on activation', async () => {
commandManager
.setup(c => c.registerCommand(TypeMoq.It.isValue(Commands.DataScience), TypeMoq.It.isAny(), TypeMoq.It.isValue(dataScience)))
.verifiable(TypeMoq.Times.once());
await dataScience.activate();
commandManager.verifyAll();
});
test('Check message from datascience command', async () => {
shell
.setup(s => s.showInformationMessage(TypeMoq.It.isValue('Hello Data Science')))
.returns(() => Promise.resolve(undefined))
.verifiable(TypeMoq.Times.once());
await dataScience.executeDataScience();
shell.verifyAll();
});
});

0 comments on commit b81aa44

Please sign in to comment.