Skip to main content

Format cells in interactive Python notebooks.

Project description

Format iPython Cells

Tests pre-commit.ci status Requires Python 3.10+ pre-commit PyPI

Python code formatter (and pre-commit hook) for cell delimiters (# %%) in VS Code-style interactive Python notebooks.

This formatter ensures

  • cell delimiters are preceded by two empty lines:

    # %% before
    foo='bar'
    # %%
    
    # %% after
    foo='bar'
    
    
    # %%
    
  • empty cells are removed:

    # %% before
    
    # %%
    
    # %% after
    
  • comments on the same line as cell delimiters are separated by a single space:

    # %%some comment before
    foo = 'bar'
    # %%    another comment
    
    # %% some comment after
    foo = 'bar'
    # %% another comment
    

Installation

pip install format-ipy-cells

Usage

CLI

format-ipy-cells path/to/file.py
# or
format-ipy-cells **/*.py

As pre-commit hook

# .pre-commit-config.yaml

repos
  - repo: https://github.com/janosh/format-ipy-cells
    rev: v0.1.10
    hooks:
      - id: format-ipy-cells

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

format-ipy-cells-0.1.11.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

format_ipy_cells-0.1.11-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page