|
12 | 12 | "\n",
|
13 | 13 | "\n",
|
14 | 14 | "\n",
|
15 |
| - " pip install importnb" |
| 15 | + " pip install importnb\n", |
| 16 | + " \n", |
| 17 | + "---\n", |
| 18 | + "\n", |
| 19 | + " conda install -c conda-forge importnb" |
16 | 20 | ]
|
17 | 21 | },
|
18 | 22 | {
|
|
30 | 34 | "source": [
|
31 | 35 | "### For brevity\n",
|
32 | 36 | "\n",
|
33 |
| - "[`importnb.loader`](src/notebooks/loader.ipynb) will find notebooks avaiable anywhere along the [`sys.path`](https://docs.python.org/2/library/sys.html#sys.path)." |
| 37 | + "[`importnb.loader`](src/notebooks/loader.ipynb) will find notebooks available anywhere along the [`sys.path`](https://docs.python.org/2/library/sys.html#sys.path)." |
34 | 38 | ]
|
35 | 39 | },
|
36 | 40 | {
|
|
151 | 155 | " import readme"
|
152 | 156 | ]
|
153 | 157 | },
|
| 158 | + { |
| 159 | + "cell_type": "markdown", |
| 160 | + "metadata": {}, |
| 161 | + "source": [ |
| 162 | + "### Docstring\n", |
| 163 | + "\n", |
| 164 | + "The first cell is the module docstring." |
| 165 | + ] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "code", |
| 169 | + "execution_count": 8, |
| 170 | + "metadata": {}, |
| 171 | + "outputs": [ |
| 172 | + { |
| 173 | + "name": "stdout", |
| 174 | + "output_type": "stream", |
| 175 | + "text": [ |
| 176 | + "__importnb__ imports notebooks as modules & packages.\n" |
| 177 | + ] |
| 178 | + } |
| 179 | + ], |
| 180 | + "source": [ |
| 181 | + " if __name__ == '__main__':\n", |
| 182 | + " print(readme.__doc__.splitlines()[0])" |
| 183 | + ] |
| 184 | + }, |
154 | 185 | {
|
155 | 186 | "cell_type": "markdown",
|
156 | 187 | "metadata": {},
|
|
179 | 210 | },
|
180 | 211 | {
|
181 | 212 | "cell_type": "code",
|
182 |
| - "execution_count": 8, |
| 213 | + "execution_count": 9, |
183 | 214 | "metadata": {},
|
184 | 215 | "outputs": [],
|
185 | 216 | "source": [
|
|
197 | 228 | },
|
198 | 229 | {
|
199 | 230 | "cell_type": "code",
|
200 |
| - "execution_count": 9, |
| 231 | + "execution_count": 10, |
201 | 232 | "metadata": {},
|
202 | 233 | "outputs": [
|
203 | 234 | {
|
|
206 | 237 | "<Signature (*, foo=42)>"
|
207 | 238 | ]
|
208 | 239 | },
|
209 |
| - "execution_count": 9, |
| 240 | + "execution_count": 10, |
210 | 241 | "metadata": {},
|
211 | 242 | "output_type": "execute_result"
|
212 | 243 | }
|
|
333 | 364 | },
|
334 | 365 | {
|
335 | 366 | "cell_type": "code",
|
336 |
| - "execution_count": 10, |
| 367 | + "execution_count": 11, |
337 | 368 | "metadata": {},
|
338 | 369 | "outputs": [
|
339 |
| - { |
340 |
| - "name": "stdout", |
341 |
| - "output_type": "stream", |
342 |
| - "text": [ |
343 |
| - "src/notebooks/capture.ipynb\n", |
344 |
| - "src/notebooks/compiler_ipython.ipynb\n", |
345 |
| - "src/notebooks/compiler_python.ipynb\n", |
346 |
| - "src/notebooks/decoder.ipynb\n", |
347 |
| - "src/notebooks/exporter.ipynb\n", |
348 |
| - "src/notebooks/loader.ipynb\n", |
349 |
| - "src/notebooks/parameterize.ipynb\n", |
350 |
| - "src/notebooks/utils/__init__.ipynb\n", |
351 |
| - "src/notebooks/utils/ipython.ipynb\n" |
352 |
| - ] |
353 |
| - }, |
354 |
| - { |
355 |
| - "name": "stderr", |
356 |
| - "output_type": "stream", |
357 |
| - "text": [ |
358 |
| - "test_import (src.importnb.tests.test_unittests.TestContext) ... " |
359 |
| - ] |
360 |
| - }, |
361 |
| - { |
362 |
| - "name": "stdout", |
363 |
| - "output_type": "stream", |
364 |
| - "text": [ |
365 |
| - "src/notebooks/utils/pytest_plugin.ipynb\n", |
366 |
| - "src/notebooks/utils/setup.ipynb\n", |
367 |
| - "src/notebooks/utils/watch.ipynb\n" |
368 |
| - ] |
369 |
| - }, |
370 | 370 | {
|
371 | 371 | "name": "stderr",
|
372 | 372 | "output_type": "stream",
|
373 | 373 | "text": [
|
374 |
| - "ok\n", |
| 374 | + "test_import (src.importnb.tests.test_unittests.TestContext) ... ok\n", |
375 | 375 | "test_reload_with_context (src.importnb.tests.test_unittests.TestContext) ... ok\n",
|
376 | 376 | "test_failure (src.importnb.tests.test_unittests.TestExtension) ... expected failure\n",
|
377 | 377 | "test_import (src.importnb.tests.test_unittests.TestExtension) ... ok\n",
|
|
380 | 380 | "test_imports (src.importnb.tests.test_unittests.TestRemote) ... skipped 'requires IP'\n",
|
381 | 381 | "\n",
|
382 | 382 | "----------------------------------------------------------------------\n",
|
383 |
| - "Ran 7 tests in 2.023s\n", |
| 383 | + "Ran 7 tests in 2.021s\n", |
384 | 384 | "\n",
|
385 | 385 | "OK (skipped=1, expected failures=1)\n"
|
386 | 386 | ]
|
|
389 | 389 | "source": [
|
390 | 390 | " if __name__ == '__main__':\n",
|
391 | 391 | " from pathlib import Path\n",
|
392 |
| - " from importnb.compiler_python import ScriptExporter\n", |
| 392 | + " from nbconvert.exporters.python import PythonExporter\n", |
| 393 | + " from importnb.compile import export\n", |
393 | 394 | " for path in Path('src/notebooks/').rglob(\"\"\"*.ipynb\"\"\"): \n",
|
394 | 395 | " if 'checkpoint' not in str(path):\n",
|
395 |
| - " src = ScriptExporter().from_filename(path)[0]\n", |
396 |
| - " try:\n", |
397 |
| - " import black\n", |
398 |
| - " src = black.format_str(src, 100)\n", |
399 |
| - " except: ...\n", |
400 |
| - "\n", |
401 |
| - " print(path)\n", |
402 |
| - " (Path('src/importnb') / path.with_suffix('.py').relative_to('src/notebooks')).write_text(src)\n", |
| 396 | + " export(path, Path('src/importnb') / path.with_suffix('.py').relative_to('src/notebooks'))\n", |
403 | 397 | " \n",
|
404 | 398 | " __import__('unittest').main(module='src.importnb.tests.test_unittests', argv=\"discover --verbose\".split(), exit=False) \n"
|
405 | 399 | ]
|
406 | 400 | },
|
407 | 401 | {
|
408 | 402 | "cell_type": "code",
|
409 |
| - "execution_count": 11, |
| 403 | + "execution_count": 12, |
410 | 404 | "metadata": {},
|
411 | 405 | "outputs": [
|
412 | 406 | {
|
413 | 407 | "name": "stdout",
|
414 | 408 | "output_type": "stream",
|
415 | 409 | "text": [
|
416 | 410 | "[NbConvertApp] Converting notebook readme.ipynb to markdown\n",
|
417 |
| - "[NbConvertApp] Writing 7132 bytes to readme.md\n" |
| 411 | + "[NbConvertApp] Writing 7121 bytes to readme.md\n" |
418 | 412 | ]
|
419 | 413 | }
|
420 | 414 | ],
|
421 | 415 | "source": [
|
422 |
| - " !jupyter nbconvert --to markdown readme.ipynb" |
| 416 | + " if __name__ == '__main__':\n", |
| 417 | + " !jupyter nbconvert --to markdown readme.ipynb" |
423 | 418 | ]
|
| 419 | + }, |
| 420 | + { |
| 421 | + "cell_type": "markdown", |
| 422 | + "metadata": {}, |
| 423 | + "source": [ |
| 424 | + " if __name__ == '__main__':\n", |
| 425 | + " from IPython.display import display, Image\n", |
| 426 | + " !pyreverse importnb -opng -pimportnb\n", |
| 427 | + " display(*map(Image, ('classes_importnb.png', 'packages_importnb.png')))" |
| 428 | + ] |
| 429 | + }, |
| 430 | + { |
| 431 | + "cell_type": "code", |
| 432 | + "execution_count": null, |
| 433 | + "metadata": {}, |
| 434 | + "outputs": [], |
| 435 | + "source": [] |
424 | 436 | }
|
425 | 437 | ],
|
426 | 438 | "metadata": {
|
|
0 commit comments