|
135 | 135 | " \"Yield cells from an exported Python file.\"\n", |
136 | 136 | " p = Path(p)\n", |
137 | 137 | " cells = p.read_text(encoding='utf-8').split(\"\\n# %% \")\n", |
| 138 | + " has_cell_number = get_config().cell_number\n", |
138 | 139 | " for cell in cells[1:]:\n", |
139 | 140 | " top,code = cell.split('\\n', 1)\n", |
140 | 141 | " try:\n", |
141 | | - " *nb,idx = top.split()\n", |
142 | | - " nb = ' '.join(nb)\n", |
| 142 | + " if has_cell_number:\n", |
| 143 | + " *nb,idx = top.split()\n", |
| 144 | + " nb = ' '.join(nb)\n", |
| 145 | + " idx = int(idx)\n", |
| 146 | + " else:\n", |
| 147 | + " nb = top\n", |
| 148 | + " idx = None\n", |
143 | 149 | " except ValueError: raise ValueError(f\"Unexpected format in '{p}' at cell:\\n```\\n# %% {cell.strip()}.\\n```\\n\"\n", |
144 | 150 | " \"The expected format is: '# %% {nb_path} {cell_idx}'.\")\n", |
145 | 151 | " nb_path = None if nb=='auto' else (p.parent/nb).resolve() # NB paths are stored relative to .py file\n", |
146 | 152 | " if code.endswith('\\n'): code=code[:-1]\n", |
147 | | - " yield AttrDict(nb=nb, idx=int(idx), code=code, nb_path=nb_path, py_path=p.resolve())" |
| 153 | + " yield AttrDict(nb=nb, idx=idx, code=code, nb_path=nb_path, py_path=p.resolve())" |
148 | 154 | ] |
149 | 155 | }, |
150 | 156 | { |
|
195 | 201 | " _def_types = ast.FunctionDef,ast.AsyncFunctionDef,ast.ClassDef\n", |
196 | 202 | " d = {}\n", |
197 | 203 | " for cell in _iter_py_cells(py_path):\n", |
198 | | - " if cell.nb == 'auto': continue\n", |
| 204 | + " if 'auto' in cell.nb: continue\n", |
199 | 205 | " loc = _nbpath2html(cell.nb_path.relative_to(nbs_path))\n", |
200 | 206 | "\n", |
201 | 207 | " def _stor(nm):\n", |
|
0 commit comments