jupytext: Wrong paired paths when syncing with the --pre-commit flag
I have the following directory structure, where the nb/test.ipynb is paired with the py/test.py.
├── nb
│   └── test.ipynb
└── py
    └── test.py
The notebook and Python file are paired with "jupytext": {"formats": "py//py,nb//ipynb"}. (using jupytext --set-formats py//py,nb//ipynb nb/test.ipynb)
This works fine when syncing with jupytext --sync nb/test.ipynb, but when syncing with jupytext --sync --pre-commit I get the following exception:
[jupytext] Notebooks in git index are:
py/test.py
[jupytext] Reading py/test.py
Traceback (most recent call last):
  File "PATH/jupytext", line 8, in <module>
    sys.exit(jupytext())
  File "PATH/jupytext/cli.py", line 292, in jupytext
    exit_code += jupytext_single_file(nb_file, args, log)
  File "PATH/jupytext/cli.py", line 389, in jupytext_single_file
    notebook, inputs_nb_file, outputs_nb_file = load_paired_notebook(notebook, fmt, nb_file, log)
  File "PATH/jupytext/cli.py", line 596, in load_paired_notebook
    for alt_path, alt_fmt in paired_paths(nb_file, fmt, formats):
  File "PATH/jupytext/paired_paths.py", line 128, in paired_paths
    raise InconsistentPath(u"Paired paths '{}' do not include the current notebook path '{}'. "
jupytext.paired_paths.InconsistentPath: Paired paths 'py/py/test.py','py/nb/test.ipynb' do not include the current notebook path 'py/test.py'. Current format is 'py:light', and paired formats are 'py//py,nb//ipynb'.
I have tried all sorts of pairings (taken from/inspired by the comments in #180), among them:
..//py,ipynb (andipynb,…//py`)nb//ipynb,..//pynb//ipynb,py//pybut they all throw a similar exception (and work fine with a regular sync).
Addition
As a current workaround I’m using jupytext --sync nb/*.ipynb in my pre-commit hook, which seems to work fine.
About this issue
- Original URL
 - State: open
 - Created 4 years ago
 - Comments: 16 (9 by maintainers)
 
Commits related to this issue
- Reproduce the conditions for #506 in a test — committed to mwouts/jupytext by mwouts 4 years ago
 - Reproduce the conditions for #506 in a test — committed to mwouts/jupytext by mwouts 4 years ago
 - Commit .py file only - and reproduce #506 — committed to mwouts/jupytext by mwouts 4 years ago
 - Reproduce the conditions for #506 in a test — committed to mwouts/jupytext by mwouts 4 years ago
 - Commit .py file only - and reproduce #506 — committed to mwouts/jupytext by mwouts 4 years ago
 - Reproduce the conditions for #506 in a test — committed to mwouts/jupytext by mwouts 4 years ago
 - Commit .py file only - and reproduce #506 — committed to mwouts/jupytext by mwouts 4 years ago
 
That’s a great solution! Didn’t know about file watchers. I suppose this works, and I guess the pre-commit hook then indeed is unnecessary.
Nonetheless, I still think the pre-commit hook should work…
About a plugin, I have some experience with JetBrains plugins, so if you want I could try to cook up a prototype some time? I guess it should be possible to register file watchers from within that plugin, and add something that does a
--set-formatswhenever a notebook file is created. I’m probably missing a lot of jupytext details/features, but I’m curious to see if something this simple would work and it could possibly be a starting point for a full-fledged plugin.Oh I see… So, indeed now I can reproduce what you see (and I’ll try to fix it).
Now, the question is what you want to do with the pre-commit. If you have the Python file tracked, then the
.ipynbnotebook will be updated when you change the.pyfile and commit. And if you edit the.ipynbfile, then Jupyter will update both files, so your setting looks fine indeed! (and is probably a better one than the one we have in the documentation 😃 ).