From 55e1ccec6795d6e0180f304fb48c4e3810c0e3ba Mon Sep 17 00:00:00 2001 From: Kerem Turgutlu Date: Fri, 21 Aug 2026 12:27:45 +0300 Subject: [PATCH] add verbose option for nb repair --- aidialog/ipynb.py | 8 ++++---- nbs/02_ipynb.ipynb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aidialog/ipynb.py b/aidialog/ipynb.py index 0ce5b15..5d2a9f9 100644 --- a/aidialog/ipynb.py +++ b/aidialog/ipynb.py @@ -133,20 +133,20 @@ def from_cells(self:Dialog, cells): return self # %% ../nbs/02_ipynb.ipynb #6bdaa293 -def reads_ipynb(txt, cls=Dialog, name='dialog'): +def reads_ipynb(txt, cls=Dialog, name='dialog', verbose=False): "Read a dialog from notebook JSON string `txt`, constructing via `cls`" nb = json.loads(txt) - if repairs := repair_nb(nb): print('NB repair:', '; '.join(repairs)) + if (repairs := repair_nb(nb)) and verbose: print('NB repair:', '; '.join(repairs)) nb = dict2nb(nb) return cls(name=name, meta=dict(nb.get('metadata', {}))).from_cells(nb.cells) # %% ../nbs/02_ipynb.ipynb #7e8912e8 -def read_ipynb(fname, cls=Dialog, name=None): +def read_ipynb(fname, cls=Dialog, name=None, verbose=False): "Read a dialog from notebook file `fname` (`.ipynb` added if missing), constructing via `cls`; `name` defaults to the file stem" f = Path(fname).expanduser() if f.suffix != '.ipynb': f = f.with_suffix('.ipynb') if not f.exists(): return print(f,'does not exist') - try: res = reads_ipynb(f.read_text(encoding='utf-8'), cls, name or f.stem) + try: res = reads_ipynb(f.read_text(encoding='utf-8'), cls, name or f.stem, verbose=verbose) except (json.JSONDecodeError, PermissionError): return res.path_ = f res.mtime_ = safe_mtime(f) diff --git a/nbs/02_ipynb.ipynb b/nbs/02_ipynb.ipynb index e0454fc..178579d 100644 --- a/nbs/02_ipynb.ipynb +++ b/nbs/02_ipynb.ipynb @@ -578,10 +578,10 @@ "outputs": [], "source": [ "#| export\n", - "def reads_ipynb(txt, cls=Dialog, name='dialog'):\n", + "def reads_ipynb(txt, cls=Dialog, name='dialog', verbose=False):\n", " \"Read a dialog from notebook JSON string `txt`, constructing via `cls`\"\n", " nb = json.loads(txt)\n", - " if repairs := repair_nb(nb): print('NB repair:', '; '.join(repairs))\n", + " if (repairs := repair_nb(nb)) and verbose: print('NB repair:', '; '.join(repairs))\n", " nb = dict2nb(nb)\n", " return cls(name=name, meta=dict(nb.get('metadata', {}))).from_cells(nb.cells)" ] @@ -594,12 +594,12 @@ "outputs": [], "source": [ "#| export\n", - "def read_ipynb(fname, cls=Dialog, name=None):\n", + "def read_ipynb(fname, cls=Dialog, name=None, verbose=False):\n", " \"Read a dialog from notebook file `fname` (`.ipynb` added if missing), constructing via `cls`; `name` defaults to the file stem\"\n", " f = Path(fname).expanduser()\n", " if f.suffix != '.ipynb': f = f.with_suffix('.ipynb')\n", " if not f.exists(): return print(f,'does not exist')\n", - " try: res = reads_ipynb(f.read_text(encoding='utf-8'), cls, name or f.stem)\n", + " try: res = reads_ipynb(f.read_text(encoding='utf-8'), cls, name or f.stem, verbose=verbose)\n", " except (json.JSONDecodeError, PermissionError): return\n", " res.path_ = f\n", " res.mtime_ = safe_mtime(f)\n",