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

Possible to set root_prefix from config file? #1033

Closed
matthewfeickert opened this issue Jan 11, 2023 · 2 comments
Closed

Possible to set root_prefix from config file? #1033

matthewfeickert opened this issue Jan 11, 2023 · 2 comments

Comments

@matthewfeickert
Copy link
Contributor

Hi. 👋 Thanks for making jupytext. In the docs it notes that format spec takes the form of

jupytext/docs/config.md

Lines 9 to 16 in b7a8dac

You can pair a notebook to as many text representations as you want (see our _World population_ notebook in the demo folder). Format specifications are of the form
```
[[root_folder//][path/][prefix]/][suffix.]ext[:format_name]
```
where
- `ext` is one of `ipynb`, `md`, `Rmd`, `jl`, `py`, `R`, `sh`, `cpp`, `q`. Use the `auto` extension to have the script extension chosen according to the Jupyter kernel.
- `format_name` (optional) is either `light` (default for scripts), `nomarker`, `percent`, `hydrogen`, `sphinx` (Python only), `spin` (R only) — see the [format specifications](formats.md).
- `root_folder`, `path`, `prefix` and `suffix` allow to save the text representation to files with different names, or in different folders (see the [configuration files examples](config.md#Configuring-paired-notebooks-globally)).

and later shows how to specify filtering on specific subdirectories

jupytext/docs/config.md

Lines 83 to 97 in b7a8dac

You can pair notebooks in trees with a `root_prefix` separated with three slashes, e.g.
```
# Pair notebooks in subfolders of 'notebooks' to scripts in subfolders of 'scripts'
formats = "notebooks///ipynb,scripts///py:percent"
```
or alternatively, using a dict to map the prefix path to the format name:
```
# Pair notebooks in subfolders of 'notebooks' to scripts in subfolders of 'scripts'
[formats]
"notebooks/" = "ipynb"
"scripts/" = "py:percent"
```
Note that if you are using a `pyproject.toml` file with this dict format, you should make sure the table header is instead `[tool.jupytext.formats]`.
The `root_prefix` is matched with the top-most parent folder of the matching name, not above the Jupytext configuration file.

This means that if I wanted to have a pyproject.toml config that would only pair notebooks to py:percent files in a directory named examples/ that I could write it as such:

[tool.jupytext]
# Always pair ipynb notebooks in examples/ directory to py:percent files
formats = ["examples///ipynb", "examples///py:percent"]

Is it currently possible to specify in the config file a root_prefix option that would allow for keeping a more (in my very subjective view) readable format like the following (which is invalid)

# THIS IS INVALID
[tool.jupytext]
root_prefix = "examples/"
# Always pair ipynb notebooks in examples/ directory to py:percent files
formats = ["ipynb", "py:percent"]

If so, can you tell me how to write it correctly?

@mwouts
Copy link
Owner

mwouts commented Jan 15, 2023

Hello @matthewfeickert , thanks for your question! Unfortunately at the moment there is no such root_prefix option in the [tool:jupytext] section of pyproject.toml files.

Does the example you gave above works? Alternatively you might use a jupytext.toml file in the examples directory (with content formats="ipynb,py:percent") to achieve the pairing just in that directory.

@matthewfeickert
Copy link
Contributor Author

Thanks for the reply, @mwouts! This is helpful — I just wanted to make sure I wasn't missing something.

Does the example you gave above works? Alternatively you might use a jupytext.toml file in the examples directory (with content formats="ipynb,py:percent") to achieve the pairing just in that directory.

Yup the working examples are viable, and I like the idea about using per directory config files. Thanks!

I'm going to close this Issue as I don't think there are any changes that are planned that might affect this in the near future.

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

No branches or pull requests

2 participants