Skip to content

Make nb metadata available to jupyter startup and kernel selection layers #8784

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/client/datascience/interactive-ipynb/nativeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
}

public async getNotebookOptions(): Promise<INotebookServerOptions> {
return this.ipynbProvider.getNotebookOptions();
const options = await this.ipynbProvider.getNotebookOptions();
const metadata = this.notebookJson.metadata;
return {
...options,
metadata
};
}

public runAllCells() {
Expand Down
9 changes: 6 additions & 3 deletions src/client/datascience/jupyter/jupyterExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as uuid from 'uuid/v4';
import { CancellationToken, Event, EventEmitter } from 'vscode';

import { nbformat } from '@jupyterlab/coreutils';
import { ILiveShareApi, IWorkspaceService } from '../../common/application/types';
import { Cancellation } from '../../common/cancellation';
import { traceInfo } from '../../common/logger';
Expand Down Expand Up @@ -248,7 +249,9 @@ export class JupyterExecutionBase implements IJupyterExecution {
// If our uri is undefined or if it's set to local launch we need to launch a server locally
if (!options || !options.uri) {
traceInfo(`Launching ${options ? options.purpose : 'unknown type of'} server`);
const launchResults = await this.startNotebookServer(options && options.useDefaultConfig ? true : false, cancelToken);
const useDefaultConfig = options && options.useDefaultConfig ? true : false;
const metadata = options?.metadata;
const launchResults = await this.startNotebookServer({useDefaultConfig, metadata}, cancelToken);
if (launchResults) {
connection = launchResults.connection;
kernelSpec = launchResults.kernelSpec;
Expand Down Expand Up @@ -284,11 +287,11 @@ export class JupyterExecutionBase implements IJupyterExecution {

// tslint:disable-next-line: max-func-body-length
@captureTelemetry(Telemetry.StartJupyter)
private async startNotebookServer(useDefaultConfig: boolean, cancelToken?: CancellationToken): Promise<{ connection: IConnection; kernelSpec: IJupyterKernelSpec | undefined }> {
private async startNotebookServer(options: {useDefaultConfig: boolean; metadata?: nbformat.INotebookMetadata}, cancelToken?: CancellationToken): Promise<{ connection: IConnection; kernelSpec: IJupyterKernelSpec | undefined }> {
// First we find a way to start a notebook server
const notebookCommand = await this.findBestCommand(JupyterCommands.NotebookCommand, cancelToken);
this.checkNotebookCommand(notebookCommand);
return this.notebookStarter.start(useDefaultConfig, cancelToken);
return this.notebookStarter.start(options, cancelToken);
}

private getUsableJupyterPythonImpl = async (cancelToken?: CancellationToken): Promise<PythonInterpreter | undefined> => {
Expand Down
5 changes: 3 additions & 2 deletions src/client/datascience/jupyter/notebookStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

'use strict';

import { nbformat } from '@jupyterlab/coreutils';
import * as cp from 'child_process';
import * as os from 'os';
import * as path from 'path';
Expand Down Expand Up @@ -56,7 +57,7 @@ export class NotebookStarter implements Disposable {
}
}
// tslint:disable-next-line: max-func-body-length
public async start(useDefaultConfig: boolean, cancelToken?: CancellationToken): Promise<{ connection: IConnection; kernelSpec: IJupyterKernelSpec | undefined }> {
public async start(options: {useDefaultConfig: boolean; metadata?: nbformat.INotebookMetadata}, cancelToken?: CancellationToken): Promise<{ connection: IConnection; kernelSpec: IJupyterKernelSpec | undefined }> {
traceInfo('Starting Notebook');
const notebookCommandPromise = this.commandFinder.findBestCommand(JupyterCommands.NotebookCommand);
// Now actually launch it
Expand All @@ -67,7 +68,7 @@ export class NotebookStarter implements Disposable {
tempDirPromise.then(dir => this.disposables.push(dir)).ignoreErrors();
// Before starting the notebook process, make sure we generate a kernel spec
const [args, kernelSpec, notebookCommand] = await Promise.all([
this.generateArguments(useDefaultConfig, tempDirPromise),
this.generateArguments(options.useDefaultConfig, tempDirPromise),
this.kernelService.getMatchingKernelSpec(undefined, cancelToken),
notebookCommandPromise
]);
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export interface INotebookServerOptions {
workingDir?: string;
interpreterPath?: string;
purpose: string;
metadata?: nbformat.INotebookMetadata;
}

export const INotebookExecutionLogger = Symbol('INotebookExecutionLogger');
Expand Down