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

Pair ipynb with files in subfolders one level down #1144

Closed hectormz closed 2 months ago

hectormz commented 11 months ago

I would like to pair .ipynb files with .py files according to this structure:

.
├── jupytext.toml
├── Alpha/
│   ├── notebooks_py/
│   │   └── notebook.py
│   └── notebook.ipynb
├── Beta/
│   ├── notebooks_py/
│   │   └── notebook.py
│   └── notebook.ipynb
└── Gamma/
    ├── notebooks_py/
    │   └── notebook.py
    └── notebook.ipynb

I haven't been able to figure this out. I am able to get it to work if I switch the locations of the .ipynb and .py files and use this in in my config:

[formats]
"notebooks_ipynb/" = "ipynb"
"./" = "py:percent"

I am open to manually pairing each .py and .ipynb pair or putting jupytext.toml config files in each project directory if that will help (Alpha, Beta, Gamma)

hectormz commented 11 months ago

I seem to be able to achieve what I want (from some other, old issues) using:

formats = "ipynb,_notebooks_py//py:percent,notebooks_md//md"

although I'm not sure what the equivalent is for the other style (for completeness)


[formats]
...
...
...
``
Maybe @mwouts has an idea. It would be good to expand the config section to cover this type of organization/pairing
VRConservation commented 4 months ago

Hi, I'm having the same issue when I use

jupytext --sync *.ipynb

It only syncs the notebooks in the folder that I cd into. So, If I have paired notebooks in separate folders, I have to cd into each folder and issue the command. Is there any way to sync across an entire folder and all subfolders?

mwouts commented 3 months ago

Hi @VRConservation , can you use the globstar operator for this?

shopt -s globstar
jupytext --sync **/*.ipynb
jupytext --sync {dir_a,dir_b,dir_c}/**/*.ipynb

@hectormz sorry that I missed this issue, indeed in the dict-like representation you can't have an empty prefix at the moment, I will fix that in a future version.

VRConservation commented 3 months ago

Thanks, Marc. I'll try this. My workaround was to create a python script in the root directory that defined the folder locations as variables then ran a for loop:

for folder in folders:
    os.chdir(folder)
    subprocess.run(["jupytext", "--sync", "*.ipynb"], check=True)
    os.chdir(orig_dir)

Depends on import os, subprocess as well as defining orig_dir.

From: Marc Wouts @.> Sent: Sunday, June 2, 2024 6:14 PM To: mwouts/jupytext @.> Cc: VRConservation @.>; Mention @.> Subject: Re: [mwouts/jupytext] Pair ipynb with files in subfolders one level down (Issue #1144)

Hi @VRConservationhttps://github.com/VRConservation , can you use the globstar operatorhttps://askubuntu.com/questions/1010707/how-to-enable-the-double-star-globstar-operator for this?

shopt -s globstar

jupytext --sync */.ipynb

jupytext --sync {dir_a,dir_b,dir_c}/*/.ipynb

@hectormzhttps://github.com/hectormz sorry that I missed this issue, indeed in the dict-like representation you can't have an empty prefix at the moment, I will fix that in a future version.

- Reply to this email directly, view it on GitHubhttps://github.com/mwouts/jupytext/issues/1144#issuecomment-2143947373, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOTZCQ6KSYLSZCRKRDUZAN3ZFNHENAVCNFSM6AAAAAA6HQ2SUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBTHE2DOMZXGM. You are receiving this because you were mentioned.Message ID: @.**@.>>