Skip to content

Commit

Permalink
Fix new notebook kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Oct 5, 2024
1 parent 554fa49 commit b5ce4dd
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
pip uninstall -y "jupyter_app_launcher" jupyterlab
- name: Upload extension packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: extension-artifacts
path: dist/jupyter_app_launcher*
Expand All @@ -63,7 +63,7 @@ jobs:
with:
python-version: '3.9'
architecture: 'x64'
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: extension-artifacts
- name: Install and Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Distributions
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: jupyter_app_launcher-releaser-dist-${{ github.run_number }}
path: .jupyter_releaser_checkout/dist
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
cd lite
jupyter lite build
- name: Upload (dist)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: jupyter-app-launcher-demo-dist-${{ github.run_number }}
path: ./lite/_output
Expand All @@ -44,7 +44,7 @@ jobs:
steps:
- name: Checkout
uses: actions/[email protected]
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: jupyter-app-launcher-demo-dist-${{ github.run_number }}
path: ./dist
Expand Down
1 change: 1 addition & 0 deletions src/factories/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { CommandsFactory } from './commands_factory';
1 change: 1 addition & 0 deletions src/factories/local_server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LocalServerFactory } from './local_server_factory';
1 change: 1 addition & 0 deletions src/factories/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { MarkdownFactory } from './markdown_factory';
1 change: 1 addition & 0 deletions src/factories/notebook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotebookFactory } from './notebook_factory';
35 changes: 17 additions & 18 deletions src/factories/notebook/notebook_factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { JupyterFrontEnd } from '@jupyterlab/application';
import { NotebookPanel } from '@jupyterlab/notebook';
import { Contents } from '@jupyterlab/services';

import { IDocumentManager } from '@jupyterlab/docmanager';
import { ILauncherConfiguration } from '../../schema';
import { IDict, IPanelFactory } from '../../token';

Expand All @@ -11,34 +10,33 @@ export class NotebookFactory implements IPanelFactory {
if (!config.sourceCode) {
return;
}
const { documentManager } = this.options;
const cwd = args['cwd'];
const app = this.options.app;
const model: Contents.IModel = await app.commands.execute(
'docmanager:new-untitled',
{
path: cwd,
type: 'notebook',
ext: '.ipynb'
}
);
const doc: NotebookPanel = await app.commands.execute('docmanager:open', {
path: model.path

const model = await documentManager.newUntitled({
path: cwd,
type: 'notebook',
ext: '.ipynb'
});
await doc.context.ready;
doc.context.model.fromString(config.sourceCode);
// doc.context.model.initialize();
let renamed = false;
let index = 0;
let newName = model.path;
while (!renamed) {
try {
await doc.context.rename(
`${config.title}${index === 0 ? '' : '-' + index}.ipynb`
);
newName = `${config.title}${index === 0 ? '' : '-' + index}.ipynb`;
await documentManager.rename(model.path, newName);
renamed = true;
} catch {
index += 1;
}
}
const doc: NotebookPanel = await app.commands.execute('docmanager:open', {
path: newName
});
await doc.context.ready;
doc.context.model.fromString(config.sourceCode);

await doc.context.save();
await doc.sessionContext.ready;
doc.content.activeCellIndex = 1;
Expand All @@ -48,5 +46,6 @@ export class NotebookFactory implements IPanelFactory {
export namespace NotebookFactory {
export interface IOptions {
app: JupyterFrontEnd;
documentManager: IDocumentManager;
}
}
1 change: 1 addition & 0 deletions src/factories/notebook_grid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotebookGridFactory } from './notebook_grid_factory';
1 change: 1 addition & 0 deletions src/factories/notebook_voila/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotebookVoilaFactory } from './notebook_voila_factory';
1 change: 1 addition & 0 deletions src/factories/terminal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TerminalFactory } from './terminal_factory';
22 changes: 13 additions & 9 deletions src/manager_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IThemeManager } from '@jupyterlab/apputils';

import { CommandsFactory } from './factories/commands/commands_factory';
import { LocalServerFactory } from './factories/local_server/local_server_factory';
import { MarkdownFactory } from './factories/markdown/markdown_factory';
import { NotebookFactory } from './factories/notebook/notebook_factory';
import { NotebookGridFactory } from './factories/notebook_grid/notebook_grid_factory';
import { NotebookVoilaFactory } from './factories/notebook_voila/notebook_voila_factory';
import { TerminalFactory } from './factories/terminal/terminal_factory';
import { CommandsFactory } from './factories/commands';
import { LocalServerFactory } from './factories/local_server';
import { MarkdownFactory } from './factories/markdown';
import { NotebookFactory } from './factories/notebook';
import { NotebookGridFactory } from './factories/notebook_grid';
import { NotebookVoilaFactory } from './factories/notebook_voila';
import { TerminalFactory } from './factories/terminal';
import { URLFactory } from './factories/url/url_factory';
import { PanelFactoryManager } from './factory_manager';
import { IPanelFactoryManager } from './token';
import { IDocumentManager } from '@jupyterlab/docmanager';

export const panelFactoryPlugin: JupyterFrontEndPlugin<IPanelFactoryManager> = {
id: 'jupyter_app_launcher:panel-factory-manager',
Expand All @@ -25,7 +26,8 @@ export const panelFactoryPlugin: JupyterFrontEndPlugin<IPanelFactoryManager> = {
IRenderMimeRegistry,
INotebookTracker,
IEditorServices,
NotebookPanel.IContentFactory
NotebookPanel.IContentFactory,
IDocumentManager
],
optional: [IThemeManager],
activate: (
Expand All @@ -34,6 +36,7 @@ export const panelFactoryPlugin: JupyterFrontEndPlugin<IPanelFactoryManager> = {
tracker: INotebookTracker,
editorServices: IEditorServices,
contentFactory: NotebookPanel.IContentFactory,
documentManager: IDocumentManager,
themeManager?: IThemeManager
): IPanelFactoryManager => {
const manager = new PanelFactoryManager();
Expand All @@ -48,7 +51,8 @@ export const panelFactoryPlugin: JupyterFrontEndPlugin<IPanelFactoryManager> = {
manager.registerFactory('notebook-grid', notebookGridFactory);

const notebookFactory = new NotebookFactory({
app
app,
documentManager
});
manager.registerFactory('notebook', notebookFactory);

Expand Down

0 comments on commit b5ce4dd

Please sign in to comment.