Skip to content

Commit

Permalink
Merge pull request #923 from microsoft/jupyterKernelExecutionApi
Browse files Browse the repository at this point in the history
Sample extension using Jupyter Execution API
  • Loading branch information
DonJayamanne authored Jan 29, 2024
2 parents 5d892cc + fb02b15 commit d1c6e39
Show file tree
Hide file tree
Showing 11 changed files with 2,144 additions and 0 deletions.
23 changes: 23 additions & 0 deletions jupyter-kernel-execution-sample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**@type {import('eslint').Linter.Config} */
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'semi': [
2,
"always"
],
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-non-null-assertion': 0,
}
};
6 changes: 6 additions & 0 deletions jupyter-kernel-execution-sample/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-toolsai.jupyter"
]
}
22 changes: 22 additions & 0 deletions jupyter-kernel-execution-sample/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"configurations": [
{
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"name": "Run Extension",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: compile",
"request": "launch",
"trace": true,
"type": "extensionHost"
}
],
"version": "0.2.0"
}
6 changes: 6 additions & 0 deletions jupyter-kernel-execution-sample/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"search.exclude": {
"out": true
},
"typescript.tsc.autoDetect": "off"
}
13 changes: 13 additions & 0 deletions jupyter-kernel-execution-sample/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"problemMatcher": ["$tsc"],
"group": "build"
}
]
}
12 changes: 12 additions & 0 deletions jupyter-kernel-execution-sample/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/*.tsbuildinfo
28 changes: 28 additions & 0 deletions jupyter-kernel-execution-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Jupyter Server Provider Sample

This is a very simple extension sample demonstrating the use of the Jupyter Extension API allowing other extensions to execute code against Jupyter Kernels.

- The sample lists finds kernels associated with notebooks that are currently open in the workspace.
- The sample the filters the kernels by language, focusing on Python kernels.
- Upon selecting a Python kernel, code selected by the user is executed against the selected kernel
- The output is displayed in an output panel.
- The sample demonstrates the ability to retrieve outputs of various mime types, including streamed output.

## Running this sample

1. `cd jupyter-kernel-execution-sample`
1. `code .`: Open the folder in VS Code
1. Run `npm install` in terminal to install the dependencies
1. Run the `Run Extension` target in the Debug View. This will:
- Start a task `npm: watch` to compile the code
- Run the extension in a new VS Code window
1. Open a Jupyter Notebook and select a Python kernel and execute some code.
1. Select the command `Jupyter Kernel API: Execute code against a Python Kernel`
1. Select the a Kernel and then select the Code to execute.
1. Watch the output panel for outputs returned by the kernel.

### Notes:

1. Make use of the `language` property of the kernel to ensure the language of the code matches the kernel.
2. `getKernel` API can can return `undefined` if the user does not grant the extension access to the kernel.
3. Access to kernels for each extension is managed via the command `Manage Access To Jupyter Kernels`.
Loading

0 comments on commit d1c6e39

Please sign in to comment.