mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.59k stars 386 forks source link

Exclude file for wild card star sync #986

Open yasirroni opened 2 years ago

yasirroni commented 2 years ago

I'm using this commands for my workflow:

jupytext --set-formats ipynb,py:percent notebooks/*.ipynb  # only the first time
jupytext --sync notebooks/*  # after i'm working

It works well. Sadly, there is another file in notebooks/ that is not .ipynb and .py, like folders or whatever extensions.

The jupytext --set-formats ipynb,py:percent notebooks/*.ipynb is great for initiate the sync, while jupytext --sync notebooks/* is great for syncing.

Changing the jupytext --sync notebooks/* to jupytext --sync notebooks/*.ipynb make the sync only work one way (if the .py files updated, jupytext revert the update).

A solution is to support exclude list:

jupytext --sync notebooks/*  --exclude *.c,*.md,archive/
mwouts commented 2 years ago

Hello @yasirroni , thanks for reaching out.

I have a few comments/questions on the above

  1. I am willing to fix jupytext --sync notebooks/*.ipynb - it should not revert the .py file!
  2. What is exactly the problem with jupytext --sync notebooks/* when non-paired files are present? I would expect the command to do nothing on non-paired files
  3. Out of curiosity, why are you not using a jupytext.toml file with formats = "ipynb,py:percent"? (It would make the first command unnecessary)
yasirroni commented 2 years ago
  1. Good.
  2. It does nothing. Just warning message, but it hurts my eyes.
  3. I only use the first command once every time a new notebook is created. Will that toml file always sync already synced file and initiate a sync (creating new .py file) for new notebook? How to use it then?
mwouts commented 2 years ago

Thank you @yasirroni for your prompt reply.

For 2, does the --quiet option remove the warning? If not, would you like to use --quiet or would you prefer another option like --ignore-unpaired-files?

Re 3 yes the value in the confit file override "formats" for notebooks that don't have a value, so you won't need the --set-formats command any more

yasirroni commented 2 years ago
  1. I don't like quite and prefer verbosity. About --ignore-unpaired-files, what is the intended behaviour of --sync? It didn't ignore unpaired? Then, what happen to single unpaired .ipynb file? It will create new .py file? With what format? It really depends on your design and what is intended behaviour.

For me, --ignore or --except following with list of file is preferred to abstract wildcard (since Jupytext support wildcard).

An ignore parameters will also help config file, for example someone what to pair all .py files except init.py

  1. Nice, I will use config file and then only use the sync, since sync is smart enough to check whether the ipynb file or py file is newer.
mwouts commented 2 years ago

Hi @yasirroni , I tried to implement a new ignore argument, but I am not sure if globs are a good fit here, as they seem strongly linked to the underlying file system. Do you see how to answer the "TODO list" on the PR #988 ? If not, do you think using regular expressions for ignore, rather than globs, would be a good option?