Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kylebarron/vscode-jupyter-python

Run automatically-inferred Python code blocks in the VS Code Jupyter extension
https://github.com/kylebarron/vscode-jupyter-python

ipython jupyter python visual-studio-code vscode vscode-extension

Last synced: about 1 month ago
JSON representation

Run automatically-inferred Python code blocks in the VS Code Jupyter extension

Awesome Lists containing this project

README

        

# vscode-jupyter-python README

Run automatically-inferred Python code blocks in Jupyter.

In this example, the **only** keyboard shortcut used is Shift+Enter:

![](https://user-images.githubusercontent.com/15164633/204451326-5ac2e334-6127-4f00-be93-4d0041405e98.gif)

This is inspired by the [Hydrogen](https://github.com/nteract/hydrogen) and [`hydrogen-python`](https://github.com/nikitakit/hydrogen-python) extensions for [Atom](https://github.com/atom/atom/).

## Install

Install from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=kylebarron.vscode-jupyter-python) or search `kylebarron.vscode-jupyter-python` in the vscode extensions search bar.

## Features

- Infer a logical "block" of code to be run at once, without needing to manually mark cell boundaries with `# %%`.

In general a "block" is the current line plus any following lines with a greater initial indentation.

_Additionally_ there's a list of keywords where the "block" of code should be expanded, even when that code appears at the same indentation level. For example:

```py
# cursor
# ↓
if x > 0:
foo()
else:
bar()
```

in this case a naive "include only code with greater indentation" would exclude the `else` clause, so `else` is included in the list of keywords where the code should be extended despite being at the initial indentation. See "extension settings" below for how to modify this list.

## Keyboard Shortcuts

By default there are two shortcuts defined:

- Cmd+Enter/Ctrl+Enter: Run an automatically-inferred code block but don't move the cursor.
- Shift+Enter: Run an automatically-inferred code block and move the cursor down to the start of the next code block.

## Requirements

This depends on the upstream [`vscode-jupyter`](https://github.com/microsoft/vscode-jupyter) extension, where this extension simply infers what text to send to `jupyter.execSelectionInteractive`.

## Extension Settings

- `vscode-jupyter-python.expandCodeList`: This list is used to determine when code that is part of the same indentation level as the starting text should be included in the inferred block. You may define your own custom elements to modify the code to your preferred behaviour. In the default setting, `else`, `elif`, `except`, `finally`, as well as all closing braces are expanded on.

## Known Issues

This is an early package so there are probably bugs.

- [ ] Support for extending block upwards (i.e. if a decorator is on the previous line, include it in the current selection)