Skip to main content

Format cells in interactive Python notebooks.

Project description

Format iPython Cells

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

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

This formatter ensures

  • cells are preceded by two empty lines:

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

    # %%
    
    # %%
    
    # %%
    
  • same-line comments are separated by a single space:

    # %%some comment
    foo = 'bar'
    # %%    another comment
    
    # %% some comment
    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

Add this to your .pre-commit-config.yaml:

repos
  - repo: https://github.com/janosh/format-ipy-cells
    rev: v0.1.7
    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.10.tar.gz (4.3 kB view hashes)

Uploaded Source

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