对Jupyter笔记本中的所有代码单元格应用黑色。
black-nb的Python项目详细描述
永不妥协的代码格式化程序,适用于Jupyter笔记本电脑
black nb将black应用于jupyter笔记本。
大部分代码取自原始的black项目,其行为故意类似。
安装
pip install black-nb
用法
将black应用于当前目录下笔记本中的所有代码单元格:
black-nb .
除了重新格式化之外,还要清除单元格输出:
black-nb --clear-output .
检查笔记本是否通过black并且没有输出(文件将保持不变):
black-nb --clear-output --check .
重新格式化*.ipynb
下的所有./
文件,不包括匹配*/outputs/*
或*/.ipynb_checkpoints/*
的路径:
black-nb --exclude '/(outputs|\.ipynb_checkpoints)/' .
命令行选项
black nb不提供许多选项。您可以通过运行black-nb --help
:
Usage: black-nb [OPTIONS] [SRC]... The uncompromising code formatter, for Jupyter notebooks. Options: -l, --line-length INTEGER How many characters per line to allow. [default: 79] --check Don't write the files back, just return the status. Return code 0 means nothing would change. Return code 1 means some files would be reformatted. Return code 123 means there was an internal error. --include TEXT A regular expression that matches files and directories that should be included on recursive searches. An empty value means all files are included regardless of the name. Use forward slashes for directories on all platforms (Windows, too). Exclusions are calculated first, inclusions later. [default: \.ipynb$] --exclude TEXT A regular expression that matches files and directories that should be excluded on recursive searches. An empty value means no paths are excluded. Use forward slashes for directories on all platforms (Windows, too). Exclusions are calculated first, inclusions later. [default: /( \.git|\.hg|\.mypy_cache|\.nox|\.tox|\.venv|_build |buck-out|build|dist|\.ipynb_checkpoints)/] -q, --quiet Don't emit non-error messages to stderr. Errors are still emitted, silence those with 2>/dev/null. -v, --verbose Also emit messages to stderr about files that were not changed or were ignored due to --exclude=. --clear-output Clear cell output as part of formatting. --config FILE Read configuration from PATH. -h, --help Show this message and exit.
版权所有
版权所有©2019 Tom Catling,Liam Coatman。
black-nb
按MIT licence的条件分布。