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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file format-ipy-cells-0.1.11.tar.gz.

File metadata

  • Download URL: format-ipy-cells-0.1.11.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for format-ipy-cells-0.1.11.tar.gz
Algorithm Hash digest
SHA256 9d2287ec9b8b661d181eec5bf31474271d0b3b02ec689341fc25227d6c9bdbf0
MD5 10df7ccd6cf3645b61d77ce381746d3c
BLAKE2b-256 4bfdca4a5575ec863ff315ef1e39207a01c3937ede88d629b4bd6bfb2a265a6f

See more details on using hashes here.

File details

Details for the file format_ipy_cells-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for format_ipy_cells-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5c45674cfa1e7b96f5945e7cc29d4e89595f17cbd1c9f6e3462121e966f11f9d
MD5 a8a95b5f72a6abf1b6b16deeb98bb92d
BLAKE2b-256 0a4ef48212cb72fa52de62e116abeaad565775a8cb3523a67ba4a95dff360013

See more details on using hashes here.

Supported by

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