Skip to content

Commit c4b7f3d

Browse files
committed
Ignore invalid pyproject.toml files in Jupytext's content manager
1 parent 1e01281 commit c4b7f3d

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Jupytext ChangeLog
88
- This version comes with a version of the JupyterLab extension that is compatible with JupyterLab 4.x. Many thanks to [Thierry Parmentelat](https://github.com/parmentelat) for his PRs! ([#1092](https://github.com/mwouts/jupytext/pull/1092), [#1109](https://github.com/mwouts/jupytext/pull/1109))
99
- Pandoc 3.0 is now supported, thanks to [Raniere Silva](https://github.com/rgaiacs) for his PR ([#1099](https://github.com/mwouts/jupytext/pull/1099))
1010
- We have reorganized the documentation and the README.md ([#1031](https://github.com/mwouts/jupytext/issues/1031), [#1073](https://github.com/mwouts/jupytext/issues/1073))
11+
- Invalid `pyproject.toml` files will be ignored by Jupytext in Jupyter ([#1103](https://github.com/mwouts/jupytext/issues/1103))
1112
- We have updated the pre-commit tools
1213

1314

jupytext/contentsmanager.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,13 @@ def get_config_file(self, directory):
515515
import toml
516516

517517
model = self.get(pyproject_path, type="file")
518-
doc = toml.loads(model["content"])
519-
if doc.get("tool", {}).get("jupytext") is not None:
520-
return pyproject_path
518+
try:
519+
doc = toml.loads(model["content"])
520+
except toml.decoder.TomlDecodeError as e:
521+
self.log.warning(f"Cannot load {pyproject_path}: {e}")
522+
else:
523+
if doc.get("tool", {}).get("jupytext") is not None:
524+
return pyproject_path
521525

522526
if not directory:
523527
return None

tests/test_contentsmanager.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,25 @@ def test_notebook_extensions_in_config(tmpdir, cwd_tmpdir):
17041704
assert model["type"] == "file"
17051705

17061706

1707+
def test_invalid_config_in_cm(tmpdir, cwd_tmpdir):
1708+
nb = new_notebook()
1709+
write(nb, "notebook.ipynb")
1710+
tmpdir.join("pyproject.toml").write(
1711+
"""[tool.jupysql.SqlMagic]
1712+
autopandas = False
1713+
displaylimit = 1"""
1714+
)
1715+
1716+
cm = jupytext.TextFileContentsManager()
1717+
cm.root_dir = str(tmpdir)
1718+
1719+
# list directory
1720+
cm.get("")
1721+
1722+
model = cm.get("notebook.ipynb")
1723+
assert model["type"] == "notebook"
1724+
1725+
17071726
def test_download_file_318(tmpdir):
17081727
tmp_ipynb = str(tmpdir.join("notebook.ipynb"))
17091728
tmp_py = str(tmpdir.join("notebook.py"))

0 commit comments

Comments
 (0)