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

Uploaded Source

File details

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

File metadata

  • Download URL: format-ipy-cells-0.1.10.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for format-ipy-cells-0.1.10.tar.gz
Algorithm Hash digest
SHA256 53053bf34f1c6a1225fad00685c2d1eafadf0cba05e11c8a78f80debe9d31fc7
MD5 6fb2a2f6be3f831fa5b7bc279691ad78
BLAKE2b-256 00942446a4b0a441dcfe7ef75848dffecae8f609411f47126327fe4c3c467870

See more details on using hashes here.

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