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

Pairing in subfolders? #1122

Open Siniara opened 1 year ago

Siniara commented 1 year ago

I have a scripts folder and I'd like all the paired notebooks to be in a notebooks folder, I have a jupytext.toml file in my project root. Just copy pasting the code from the readme has no effect.

jupytext=1.15.0

My dev environment is VS Code if that might affect something. I use the jupyter extension there. The config file seems to be read as if I change the script format from percent to light it registers that change, but not the folder structure.

Folder structure:

project
    -/scripts
    -jupytext.toml 

jupytext.toml contents:

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

then run

jupytext --set-formats py,ipynb scripts/*.py

This creates paired notebooks in the scripts folder. I would have expected the notebooks folder to be created. I also tried creating it on my own to no effect.

hectormz commented 11 months ago

Hi @Siniara I use a similar jupytext.toml and it works fine. I'm not sure if the issue is due to using Jupyter in VS Code. I use normal Jupyter Lab that runs in my browser. I have never had to run your jupytext command.

I believe I have always made the subfolders myself. I'm not sure jupytext will create the subfolders in your config file.

mwouts commented 6 months ago

Hey @Siniara , sorry I missed this one. Maybe you meant to use jupytext --sync rather than --set-formats (which sets a configuration per notebook)?

e-dorigatti commented 1 month ago

I have the same issue: the paired scripts are created in the same folder as the notebooks (jupytext 1.16.4).

The examples below are via CLI (all commands executed in the project's root folder), but I get the same result using the Jupyter web UI.

Jupytext can find the configuration file:

$ python
>>> from jupytext.config import find_jupytext_configuration_file
>>> find_jupytext_configuration_file('.')
'./pyproject.toml'

And the configuration file is as recommended in the documentation:

$ tail -n 4 pyproject.toml 

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

The scripts/ folder exists.

When using Jupytext from the web UI, I created the equivalent notebooks/jupytext.toml, so that find_jupytext_configuration_file also works when executed from within the notebook.

Syncing does not create any new files:

$ jupytext --sync notebooks/test.ipynb 
[jupytext] Reading notebooks/test.ipynb in format ipynb
[jupytext] Unchanged notebooks/test.ipynb

While manually converting creates the file in the wrong directory:

$ jupytext --to py:percent notebooks/test.ipynb
[jupytext] Reading notebooks/test.ipynb in format ipynb
[jupytext] Writing notebooks/test.py in format py:percent

And manually specifying the formats uses the wrong directory:

$ jupytext --set-formats ipynb,py notebooks/test.ipynb 
[jupytext] Reading notebooks/test.ipynb in format ipynb
[jupytext] Updating notebook metadata with '{"jupytext": {"formats": "ipynb,py"}}'
[jupytext] Loading notebooks/test.py
[jupytext] Updating notebooks/test.ipynb
[jupytext] Unchanged notebooks/test.py