https://github.com/janosh/format-ipy-cells
Code formatter for iPython cells
https://github.com/janosh/format-ipy-cells
auto-formatter ipython-notebook pre-commit pre-commit-hook
Last synced: 7 months ago
JSON representation
Code formatter for iPython cells
- Host: GitHub
- URL: https://github.com/janosh/format-ipy-cells
- Owner: janosh
- License: mit
- Created: 2021-04-29T16:40:46.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-06T16:32:54.000Z (over 1 year ago)
- Last Synced: 2025-02-01T10:51:11.827Z (over 1 year ago)
- Topics: auto-formatter, ipython-notebook, pre-commit, pre-commit-hook
- Language: Python
- Homepage: https://pypi.org/project/format-ipy-cells
- Size: 45.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Format iPython Cells
[](https://github.com/janosh/format-ipy-cells/actions/workflows/test.yml)
[](https://results.pre-commit.ci/latest/github/janosh/format-ipy-cells/main)
[](https://python.org/downloads)
[](https://github.com/pre-commit/pre-commit)
[](https://pypi.org/project/format-ipy-cells)
Python code formatter (and [`pre-commit`](https://pre-commit.com) hook) for cell delimiters (`# %%`) in [VS Code-style interactive Python notebooks](https://code.visualstudio.com/docs/python/jupyter-support-py).
This formatter ensures
- cell delimiters are preceded by two empty lines:
```py
# %% before
foo='bar'
# %%
```
```py
# %% after
foo='bar'
# %%
```
- empty cells are removed:
```py
# %% before
# %%
```
```py
# %% after
```
- comments on the same line as cell delimiters are separated by a single space:
```py
# %%some comment before
foo = 'bar'
# %% another comment
```
```py
# %% some comment after
foo = 'bar'
# %% another comment
```
## Installation
```sh
pip install format-ipy-cells
```
## Usage
### CLI
```sh
format-ipy-cells path/to/file.py
# or
format-ipy-cells **/*.py
```
### As `pre-commit` hook
```yml
# .pre-commit-config.yaml
repos
- repo: https://github.com/janosh/format-ipy-cells
rev: v0.1.10
hooks:
- id: format-ipy-cells
```