过滤.ipynb(nbformat)文件以改进与版本控制系统(VCS)的集成
nbfilter的Python项目详细描述
nbfilter
过滤.ipynb
(^{
设置
从PyPI安装:
pip install nbfilter
从命令行使用:
python -m nbfilter.clean < research.ipynb | sponge research.ipynb
融入git
:
从存储库的根目录:
运行以下命令以在.git/config
设置中定义名为ipynbfilter
的筛选器:
git config filter.ipynbfilter.clean 'python -m nbfilter.clean'
然后运行以下命令序列之一,为所有扩展名为.ipynb
的文件触发它:
printf'*.ipynb filter=ipynbfilter\n' >> .gitattributes # Apply filter for all contributors git add .gitattributes
或:
printf'*.ipynb filter=ipynbfilter\n' >> .git/info/attributes # Apply filter for just me
将其应用于已受源代码管理的文件(例如,使随后的更改产生更清晰的结果):
git add --renormalize . # (re-)apply filters to all files currently under source control
或:
git add --renormalize research.ipynb # (re-)apply filters to a single file
参考/备选方案
Min RK的^{
} gist 启动了这一切(授权为“公共域”)。git pre-commit hook for stripping output from IPython notebooks
^{
} 是一个PyPI-published包,它通过nbstripout
控制台脚本提供所有功能。stackoverflow问题:Using IPython notebooks under version control
Making Git and Jupyter Notebooks play nice 为了提高速度,使用^{
} 而不是python进行json修改。Jupyter notebooks and version control 讨论了
.ipynb
文件格式的替代方案,这种格式本可以改进git diff
ing (具体来说,yaml有一些附加的约束)。
许可证
版权所有(c)2018克里斯托弗·布朗。MIT Licensed。