Skip to content

Commit

Permalink
Follow up on #830 (#845)
Browse files Browse the repository at this point in the history
* Follow-up on #830

* Update CHANGELOG.md

* In the contentsmanager we must use get() to load the pyproject.toml file
  • Loading branch information
mwouts authored Aug 31, 2021
1 parent e4dbfc5 commit e97819f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Jupytext ChangeLog
1.11.5+dev (2021-09-??)
-----------------------

**Added**
- Jupytext can be configured through the `pyproject.toml` file. Thanks to Robin Brown for this contribution! (#828)

**Fixed**
- Added more test to make sure that notebooks can be trusted. In practice, notebooks could not be trusted in JupyterLab<3.0.13 because of the absence of cell ids (#826)


1.11.5 (2021-08-31)
-------------------
Expand Down
9 changes: 8 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ or alternatively, using an explicit format list:
formats = ["ipynb", "py:percent"]
```

If you wish to use the `pyproject.toml` config file rather than `jupytext.toml`, you just need to
create a `[tool.jupytext]` section in the `pyproject.toml` file, like here:
```
[tool.jupytext]
formats = "ipynb,py:percent"
```

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'
Expand All @@ -84,7 +91,7 @@ or alternatively, using a dict to map the prefix path to the format name:
"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]`
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.

Expand Down
1 change: 0 additions & 1 deletion jupytext/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ def parse_jupytext_configuration_file(jupytext_config_file, stream=None):
import toml

doc = toml.loads(stream)
print(jupytext_config_file)
if jupytext_config_file.endswith(PYPROJECT_FILE):
return doc["tool"]["jupytext"]
else:
Expand Down
7 changes: 6 additions & 1 deletion jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,12 @@ def get_config_file(self, directory):

pyproject_path = directory + "/" + PYPROJECT_FILE
if self.file_exists(pyproject_path):
return pyproject_path
import toml

model = self.get(pyproject_path, type="file")
doc = toml.loads(model["content"])
if doc.get("tool", {}).get("jupytext") is not None:
return pyproject_path

if not directory:
return None
Expand Down

0 comments on commit e97819f

Please sign in to comment.