Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure notebook pairing using regex/fnmatch/glob patterns #974

Open
Jacob-Stevens-Haas opened this issue Jul 6, 2022 · 6 comments · May be fixed by #988
Open

Configure notebook pairing using regex/fnmatch/glob patterns #974

Jacob-Stevens-Haas opened this issue Jul 6, 2022 · 6 comments · May be fixed by #988

Comments

@Jacob-Stevens-Haas
Copy link

Jacob-Stevens-Haas commented Jul 6, 2022

I have a library with examples in the examples folder. Each example is its own subfolder, containing:

  • example.py (want to sync)
  • example.ipynb (want to sync)
  • utils.py (helper functions for example.py/ipynb - don't sync)

In pyproject.toml, I tried setting:

[tool.jupytext]
formats = "examples/*/example.ipynb///ipynb,examples/*/example.py///py:percent"

However, jupytext would not find & correct my file either with pre-commit run --all or jupytext --pre-commit --sync

Failing the above, I also can't seem to set pairings individually in pyproject.toml or in .pre-commit-config.yaml. For the latter, I tried:

- repo: https://github.com/mwouts/jupytext
  rev: v1.14.0
  hooks:
    - id: jupytext
      args: ["--set-formats", "ipynb,py", "examples/2_introduction_to_sindy/example.py", "--sync"]

But I got the error:

...
jupytext: error: unrecognized arguments: <list of most of the files in my repo>

How do I achieve this?

@abhishekmittal15
Copy link

This is something I need too. To be able to specify the config in pyproject.toml only for certain notebooks and not for all notebooks. I see a merge here, but not sure if the merge addressed this issue. Has the issue been resolved @Jacob-Stevens-Haas ?

@Jacob-Stevens-Haas
Copy link
Author

@abhishekmittal15 , that PR was on the repository I work on, mentioning that we can't add jupytext as a pre-commit until this issue is resolved.

@mwouts
Copy link
Owner

mwouts commented Jul 25, 2022

Hi @Jacob-Stevens-Haas , sorry for not answering this before. The following did work in my test:

[tool.jupytext]
formats = "examples//example/ipynb,examples//example/py:percent"

The first "examples" is the root folder where you require paired files to be, and the second "example" is the required name prefix.

I do agree that we should give more details about this the documentation, I'll keep a note of that on my todo list.

Regarding your second question, local configuration files do work (and if you don't need to filter the root folder then the syntax is just formats = "example/ipynb,example/py:percent" if you are just willing to filter on an example prefix). I think what was did not work in the attempt documented above is the explicit file name in the args argument of the pre-commit hook.

@Jacob-Stevens-Haas
Copy link
Author

Jacob-Stevens-Haas commented Jul 25, 2022

Thanks @mwouts, works better, but is there a way to exclude files like examples//example_data.py? All of my example notebooks offload data generation to those modules.

I also get warnings for extraneous files that are not paired:

[jupytext] Reading test/utils/test_axes.py in format py
[jupytext] Warning: test/utils/test_axes.py is not a paired notebook

I tried silencing these with -q, but instead of silencing the warnings, it silenced the errors and left the warnings! i.e.

[jupytext] Updating examples/2_introduction_to_sindy/example_data.ipynb

no longer appears.

Also, I tried to run jupytext outside of pre-commit with jupytext --sync --pre-commit, but is there a way to get the effect of pre-commit run -all? In the interim, I've made some test changes to the repo so I can enter the debugger and see how pairs.py and config.py are working.

@Jacob-Stevens-Haas
Copy link
Author

FWIW, I think the DeprecationWarning here should be a UserWarning, since DeprecationWarning is ignored by default unless raised in __main__ module. If I understand correctly, DeprecationWarning would make sense if client libraries were using cli.py.

@mwouts
Copy link
Owner

mwouts commented Jul 29, 2022

Hello @Jacob-Stevens-Haas , thank you for your previous remarks

is there a way to exclude files like examples//example_data.py?

No, there is no way to do so. The filtering is only on the folder / prefix or suffix (and I don't have the bandwidth to change that)

I tried silencing these with -q, but instead of silencing the warnings, it silenced the errors and left the warnings!

The warning on unpaired files was also noticed at #986. Maybe we could remove that warning and simply issue a warning if --sync is used but no paired file is found among the arguments... What do you think?

I tried to run jupytext outside of pre-commit with jupytext --sync --pre-commit, but is there a way to get the effect of pre-commit run -all?

Yes, as you probably found out, it's --pre-commit-mode, cf.

entry: jupytext --pre-commit-mode

I think the DeprecationWarning here should be a UserWarning,

Do you mean the warning does not appear at the command line? If so yes sure a UserWarning would be a better fit, certainly.

@mwouts mwouts linked a pull request Aug 14, 2022 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants