跳转到主要内容

格式化交互式Python笔记本中的单元格。

项目描述

格式化iPython单元格

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

Python代码格式化器(和pre-commit钩子)用于VS Code风格的交互式Python笔记本中的单元格分隔符(# %%)。

此格式化器确保:

  • 单元格分隔符之前有两行空行

    # %% before
    foo='bar'
    # %%
    
    # %% after
    foo='bar'
    
    
    # %%
    
  • 删除空单元格

    # %% before
    
    # %%
    
    # %% after
    
  • 与单元格分隔符在同一行的注释之间用一个空格分隔

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

安装

pip install format-ipy-cells

使用

命令行界面

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

作为pre-commit钩子

# .pre-commit-config.yaml

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

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分发

format-ipy-cells-0.1.11.tar.gz (6.1 kB 查看哈希值)

上传时间:

构建分发

format_ipy_cells-0.1.11-py3-none-any.whl (5.1 kB 查看哈希值)

上传时间 Python 3

支持者