question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong paired paths when syncing with the --pre-commit flag

See original GitHub issue

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 (and ipynb,…//py`)
  • nb//ipynb,..//py
  • nb//ipynb,py//py but 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
slideclimbcommented, May 24, 2020

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-formats whenever 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.

1reaction
mwoutscommented, May 19, 2020

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 .ipynb notebook will be updated when you change the .py file and commit. And if you edit the .ipynb file, 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 😃 ).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported hooks - pre-commit
perlcritic - Runs `perlcritic`, requires script in PATH ... codemeta-description-updated - make sure `codemeta.json` is in sync with `DESCRIPTION`.
Read more >
Jupytext ChangeLog
Jupyter will show the diff between text and ipynb paired notebooks when it cannot ... Fixed wrong paired paths when syncing with the...
Read more >
How to configure pre-commit-config.yaml to work with poetry?
that said, you can escape the supported path as you're doing with language: ... encountering problems is because you're holding it wrong :) ......
Read more >
Web service error codes (Microsoft Dataverse) - Power Apps
Message: Active Stage ID '{0}' does not match last Stage ID in Traversed Path '{1}'. Please contact your system administrator. 0x80060449 - ...
Read more >
All Configurations | Apache Hudi
Comma separated list of file paths to read within a Hudi table. ... Flag to indicate whether to ignore any non exception error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found