git 中忽略笔记本时的 Jupytext 预提交配置

Jupytext pre-commit config when notebooks are ignored in git

我现在的钩子是这样的:

-   repo: local
    hooks:
    -   id: jupytext
        name: jupytext
        entry: jupytext
        language: conda
        files: '^notebooks/(.*\.py|.*\.ipynb)$'
        args: [--sync, --pipe, black]

目录结构是这样的:

.
├── notebooks
│   └── dataset-exploration
│       └── 01-amplitude-exploration
│           └── amplitude_exploration.ipynb
├── [other folders]*

我的 .gitignore 文件中有 *.ipynb,这意味着笔记本会被忽略(因为 git 大小问题),但我希望预提交自动 create/sync python 脚本及其在每次提交中的配对笔记本。但显然是因为我的钩子没有按预期工作,并且没有从我的 *.ipynb 文件生成(或同步)*.py 文件。

pre-commit 只对签入的文件进行操作——因为你的文件被 gitignore 了,你需要找到一些其他的方式来同步它们

一个想法是 always_run: truepass_filenames: false 并列出要显式同步的笔记本:

-   repo: local
    hooks:
    -   id: jupytext
        name: jupytext
        entry: jupytext --sync --pipe black notebooks/foo.ipynb notebooks/bar.ipynb
        language: conda
        always_run: true
        pass_filenames: false

虽然这违背了框架的目的(你总是 运行 运行缓慢)


免责声明:我创建了预提交