mwouts / jupytext

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

Allow to provide the output argument when providing multiple files with --set-formats #1223

Closed Siniara closed 5 months ago

Siniara commented 6 months ago

jupytext 1.16.1

Currently, when running jupytext --set-formats you can specify either a single file or multiple files, e.g., jupytext --set-formats ipynb,py /notebooks/*.ipynb. However, you cannot specify an output for multiple files.

>>>jupytext --set-formats ipynb,py notebooks/*.ipynb --output scripts/notebooks/
ValueError: Please input a single notebook when using --output

I think it would be useful to allow users to specify an output folder where are the synced files would be put. This would also allow to circumvent the seeming jupytext limitation in VSCode that I posted a year or so ago: https://github.com/mwouts/jupytext/issues/1122.

It seems that when running commands from the command line configuration files are ignored, but if that's the case then there's no nice way to set up a different folder for syncing files if not using JupyterLab server and working directly in VSCode for example. The only solution I see is to write a bash script that runs the command for every .ipynb file in the notebooks directory.

mwouts commented 6 months ago

Hello @Siniara , thanks for reaching out!

Do I understand correctly that you want to sync your notebooks from the notebooks/ folder, to scripts in scripts/notebooks/?

I would expect that you could create a jupytext.toml configuration file with this content:

[formats]
"notebooks/" = "ipynb"
"scripts/notebooks/" = "py:percent"

and then simply run jupytext --sync notebooks/*.

It seems that when running commands from the command line configuration files are ignored

I don't expect that. What OS are you using? What is the outcome of find_jupytext_configuration_file (see https://jupytext.readthedocs.io/en/latest/config.html) ?