Skip to content
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

feat(jupyter): add args to notebook metadata #65

Merged
merged 1 commit into from
Jan 31, 2024
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
17 changes: 17 additions & 0 deletions packages/libro-jupyter/src/libro-jupyter-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { VirtualizedManager } from '@difizen/libro-core';
import {
ContentsManager,
ExecutableNotebookModel,
isDisplayDataMsg,
LibroKernelConnectionManager,
ServerConnection,
ServerManager,
Expand All @@ -16,6 +17,7 @@ import { l10n } from '@difizen/mana-l10n';

import {
ExecutedWithKernelCellModel,
libroArgsMimetype,
LibroFileService,
} from './libro-jupyter-protocol.js';
import { SaveFileErrorModal } from './toolbar/save-file-error.js';
Expand Down Expand Up @@ -81,6 +83,21 @@ export class LibroJupyterModel extends LibroModel implements ExecutableNotebookM
this.modalService = modalService;
this.dndAreaNullEnable = true;
this.virtualizedManager = virtualizedManagerHelper.getOrCreate(this);
this.kcReady
.then(() => {
this.kernelConnection?.futureMessage((msg) => {
if (isDisplayDataMsg(msg) && libroArgsMimetype in msg.content.data) {
this.metadata = {
...this.metadata,
args: msg.content.data[libroArgsMimetype],
};
}
});
return;
})
.catch(() => {
return;
});
}

get isKernelIdle() {
Expand Down
2 changes: 2 additions & 0 deletions packages/libro-jupyter/src/libro-jupyter-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ export const ServerLaunchManager = Symbol('ServerLaunchManager');
export interface ServerLaunchManager {
launch: () => Promise<any>;
}

export const libroArgsMimetype = 'application/vnd.libro.args+json';
9 changes: 9 additions & 0 deletions packages/libro-kernel/src/kernel/kernel-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export class KernelConnection implements IKernelConnection {
return this.iopubMessageEmitter.event;
}

get futureMessage(): ManaEvent<KernelMessage.IMessage<KernelMessage.MessageType>> {
return this.futureMessageEmitter.event;
}

/**
* A signal emitted for unhandled kernel message.
*
Expand Down Expand Up @@ -381,6 +385,7 @@ export class KernelConnection implements IKernelConnection {
this.statusChangedEmitter.dispose();
this.onDisposedEmitter.dispose();
this.iopubMessageEmitter.dispose();
this.futureMessageEmitter.dispose();
this.anyMessageEmitter.dispose();
this.pendingInputEmitter.dispose();
this.unhandledMessageEmitter.dispose();
Expand Down Expand Up @@ -1529,6 +1534,7 @@ export class KernelConnection implements IKernelConnection {
const future = this._futures?.get(parentHeader.msg_id);
if (future) {
await future.handleMsg(msg);
this.futureMessageEmitter.fire(msg);
this._assertCurrentMessage(msg);
} else {
// If the message was sent by us and was not iopub, it is orphaned.
Expand Down Expand Up @@ -1756,6 +1762,9 @@ export class KernelConnection implements IKernelConnection {
protected connectionStatusChangedEmitter = new Emitter<ConnectionStatus>();
protected onDisposedEmitter = new Emitter<void>();
protected iopubMessageEmitter = new Emitter<KernelMessage.IIOPubMessage>();
protected futureMessageEmitter = new Emitter<
KernelMessage.IMessage<KernelMessage.MessageType>
>();
protected anyMessageEmitter = new Emitter<IAnyMessageArgs>();
protected pendingInputEmitter = new Emitter<boolean>();
protected unhandledMessageEmitter = new Emitter<KernelMessage.IMessage>();
Expand Down
1 change: 1 addition & 0 deletions packages/libro-kernel/src/kernel/libro-kernel-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ export interface IKernelConnection extends ObservableDisposable {
*/
iopubMessage: Event<KernelMessage.IIOPubMessage>;

futureMessage: Event<KernelMessage.IMessage<KernelMessage.MessageType>>;
/**
* A signal emitted for unhandled non-iopub kernel messages that claimed to
* be responses for messages we sent using this kernel object.
Expand Down
Loading