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.

[PRECOMMIT] JuPyText does not preserve ids during pre-commit hook bidirectional sync.

See original GitHub issue

I recently tried to upgrade habitat_sim to use the new pre-commit hook, but found that the ID is not preserved in the cells with a bidirectional update.

pre-commit hook settings

-   repo: https://github.com/mwouts/jupytext/
    rev: v1.11.1
    hooks:
    -   id: jupytext
        files: '^examples/tutorials/(colabs|nb_python)/(.*\.py|.*\.ipynb)$'
        args: [--update-metadata, '{"jupytext":{"notebook_metadata_filter":"all", "cell_metadata_filter":"-all"}, "accelerator":"GPU"}', --set-formats, 'nb_python//py:percent,colabs//ipynb,', --pipe, black, --pipe, 'isort - --treat-comment-as-code "# %%"', --pipe-fmt, 'py:percent', --sync]
        additional_dependencies:
            - black
            - isort

I also tried this simplified version here:

-   repo: https://github.com/mwouts/jupytext/
    rev: v1.11.1
    hooks:
    -   id: jupytext
        files: '^examples/tutorials/nb_python/.*\.py$'
        args: [--update-metadata, '{"jupytext":{"notebook_metadata_filter":"all", "cell_metadata_filter":"-all"}, "accelerator":"GPU"}', --set-formats, 'nb_python//py:percent,colabs//ipynb,', --pipe, black, --pipe, 'isort - --treat-comment-as-code "# %%"', --pipe-fmt, 'py:percent', --sync]
        additional_dependencies:
            - black
            - isort

but ran into the same problem where it would keep updating the id every time pre-commit is run.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwoutscommented, May 2, 2021

Update JuPyText hook so the version comment in all the .py files change.

Oh interesting! I’ve seen people using

notebook_metadata_filter: -jupytext.text_representation.jupytext_version,-jupytext.text_representation.format_version

to avoid this impact on their text notebooks (yet I am not sure I would recommend that because then I can’t provide version compatibility)

Let me know if there is anything else I can do to help.

0reactions
Skylion007commented, May 2, 2021

My best guess is it was this corner case.

  • Update JuPyText hook so the version comment in all the .py files change.
  • Update NBConvert so that the notebook format changes.
  • These changes conflict so jupytext will try to update both. Doing this will change the ID for every run of JuPyText.
  • Pre-Commit hook will never pass due to constantly changing ID I just tried to reproduce it though by only updating nbconvert and it didn’t work, so I suspect it’s when BOTH are updated at the same time. It was a pretty big version change though 1.6 -> to current so I don’t know if it was a one off bug.

Basically it was happening before / after this PR: https://github.com/facebookresearch/habitat-sim/pull/1200 (with the nbconvert constraint removed).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supported hooks - pre-commit
reorder-python-imports - This hook reorders imports in python files. ... forbid-html-img-without-alt-text - List every <img> tag without a alt= or ...
Read more >
Using as a pre-commit hook - Jupytext documentation
Tested examples of how to use the pre-commit hook are available in our tests - see for instance test_pre_commit_1_sync_with_config.py.
Read more >
Jupytext pre-commit config when notebooks are ignored in git
gitignore file, which means that notebooks are ignored (because of git size issues), but I want pre-commit to automatically create/sync python ...
Read more >
Proceedings of the 21st Python in Science Conference
its application is not limited to astronomy, but suitable for much of scientific and engineering data, as well as models. We finish.
Read more >
What if Git worked with programming languages? - Hacker News
Not every file in source control is source code. Not every programming language's grammar maps to an abstract syntax tree.
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