Metadata-Version: 2.1
Name: format-ipy-cells
Version: 0.1.11
Summary: Format cells in interactive Python notebooks.
Author-email: Janosh Riebesell <janosh.riebesell@gmail.com>
License: MIT License
        
        Copyright (c) 2021 Janosh Riebesell
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        The software is provided "as is", without warranty of any kind, express or
        implied, including but not limited to the warranties of merchantability,
        fitness for a particular purpose and noninfringement. In no event shall the
        authors or copyright holders be liable for any claim, damages or other
        liability, whether in an action of contract, tort or otherwise, arising from,
        out of or in connection with the software or the use or other dealings in the
        software.
        
Project-URL: Homepage, https://github.com/janosh/format-ipy-cells
Project-URL: Package, https://pypi.org/project/format-ipy-cells
Keywords: code formatting,interactive,ipython,jupyter,pre-commit hook,python
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"

# Format iPython Cells

[![Tests](https://github.com/janosh/format-ipy-cells/actions/workflows/test.yml/badge.svg)](https://github.com/janosh/format-ipy-cells/actions/workflows/test.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/janosh/format-ipy-cells/main.svg)](https://results.pre-commit.ci/latest/github/janosh/format-ipy-cells/main)
[![Requires Python 3.10+](https://img.shields.io/badge/Python-3.10+-blue.svg?logo=python&logoColor=white)](https://python.org/downloads)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![PyPI](https://img.shields.io/pypi/v/format-ipy-cells?logo=pypi&logoColor=white)](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
```
