|
316 | 316 | " recursive=get_config().recursive\n", |
317 | 317 | " res = globtastic(path, file_glob=file_glob, skip_folder_re=skip_folder_re,\n", |
318 | 318 | " skip_file_re=skip_file_re, recursive=recursive, **kwargs)\n", |
319 | | - " return res.map(Path) if as_path else res" |
| 319 | + " res = res.map(Path) if as_path else res\n", |
| 320 | + " return res" |
320 | 321 | ] |
321 | 322 | }, |
322 | 323 | { |
|
354 | 355 | " **kwargs):\n", |
355 | 356 | " \"Export notebooks in `path` to Python modules\"\n", |
356 | 357 | " if os.environ.get('IN_TEST',0): return\n", |
357 | | - " files = nbglob(path=path, **kwargs)\n", |
| 358 | + " files = nbglob(path=path, as_path=True, **kwargs).sorted('name')\n", |
358 | 359 | " for f in files: nb_export(f)\n", |
359 | 360 | " add_init(get_config().lib_path)\n", |
360 | 361 | " _build_modidx()" |
361 | 362 | ] |
362 | 363 | }, |
| 364 | + { |
| 365 | + "cell_type": "markdown", |
| 366 | + "metadata": {}, |
| 367 | + "source": [ |
| 368 | + "When exporting the notebooks, they should be exported in order of the filename to ensure deterministic build behaviour. The below test patches `nbglob` to return a non-ordered list, then checks that `nb_export` is still called on the notebooks in the right order:" |
| 369 | + ] |
| 370 | + }, |
| 371 | + { |
| 372 | + "cell_type": "code", |
| 373 | + "execution_count": null, |
| 374 | + "metadata": {}, |
| 375 | + "outputs": [], |
| 376 | + "source": [ |
| 377 | + "from copy import copy\n", |
| 378 | + "\n", |
| 379 | + "\n", |
| 380 | + "class EscapeException(Exception):\n", |
| 381 | + " pass\n", |
| 382 | + "\n", |
| 383 | + "def nb_export_mock(nb_path: str):\n", |
| 384 | + " expected = expected_order.pop()\n", |
| 385 | + " assert nb_path==expected, f'Expected {expected}, got {nb_path}'\n", |
| 386 | + " \n", |
| 387 | + " # escape from the outer function as the tests are done\n", |
| 388 | + " if not expected_order:\n", |
| 389 | + " raise EscapeException()\n", |
| 390 | + " \n", |
| 391 | + "# replace those functions by mocks, saving the original objects\n", |
| 392 | + "nbglob_save = copy(nbglob)\n", |
| 393 | + "nb_export_save = copy(nb_export)\n", |
| 394 | + "\n", |
| 395 | + "nbglob = lambda *args, **kwargs: L(['../../8.ipynb', 'api/3.ipynb', '4.ipynb']).map(Path)\n", |
| 396 | + "\n", |
| 397 | + "expected_order = reversed(L(['api/3.ipynb', '4.ipynb', '../../8.ipynb']).map(Path))\n", |
| 398 | + "#expected_order.reverse()\n", |
| 399 | + "nb_export = nb_export_mock\n", |
| 400 | + "\n", |
| 401 | + "try:\n", |
| 402 | + " nbdev_export()\n", |
| 403 | + "except EscapeException:\n", |
| 404 | + " pass # this silences the exception used to end nbdev_export early\n", |
| 405 | + "\n", |
| 406 | + "# restore original objects to make sure the notebook runs as intended\n", |
| 407 | + "nbglob = nbglob_save\n", |
| 408 | + "nb_export = nb_export_save" |
| 409 | + ] |
| 410 | + }, |
363 | 411 | { |
364 | 412 | "cell_type": "markdown", |
365 | 413 | "metadata": {}, |
|
556 | 604 | "text/markdown": [ |
557 | 605 | "---\n", |
558 | 606 | "\n", |
559 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L209){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 607 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L211){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
560 | 608 | "\n", |
561 | 609 | "### NbdevLookup.doc\n", |
562 | 610 | "\n", |
|
567 | 615 | "text/plain": [ |
568 | 616 | "---\n", |
569 | 617 | "\n", |
570 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L209){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 618 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L211){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
571 | 619 | "\n", |
572 | 620 | "### NbdevLookup.doc\n", |
573 | 621 | "\n", |
|
650 | 698 | "text/markdown": [ |
651 | 699 | "---\n", |
652 | 700 | "\n", |
653 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L214){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 701 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
654 | 702 | "\n", |
655 | 703 | "### NbdevLookup.code\n", |
656 | 704 | "\n", |
|
661 | 709 | "text/plain": [ |
662 | 710 | "---\n", |
663 | 711 | "\n", |
664 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L214){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 712 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L216){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
665 | 713 | "\n", |
666 | 714 | "### NbdevLookup.code\n", |
667 | 715 | "\n", |
|
709 | 757 | "text/markdown": [ |
710 | 758 | "---\n", |
711 | 759 | "\n", |
712 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 760 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L233){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
713 | 761 | "\n", |
714 | 762 | "### NbdevLookup.linkify\n", |
715 | 763 | "\n", |
|
718 | 766 | "text/plain": [ |
719 | 767 | "---\n", |
720 | 768 | "\n", |
721 | | - "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L231){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 769 | + "[source](https://github.com/fastai/nbdev/blob/master/nbdev/doclinks.py#L233){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
722 | 770 | "\n", |
723 | 771 | "### NbdevLookup.linkify\n", |
724 | 772 | "\n", |
|
0 commit comments