|
64 | 64 | "nbdev is heavily customizeable, thanks to the configuration system defined in this module. There are 2 ways to interact with nbdev's config:\n", |
65 | 65 | "\n", |
66 | 66 | "- **In the terminal:** `nbdev_create_config` creates a config file (if you're starting a new project use `nbdev_new` instead)\n", |
67 | | - "- **In your library:** `get_config` returns a [`Config`](https://fastcore.fast.ai/foundation.html#config) object.\n", |
| 67 | + "- **In your library:** `get_config` returns a `fastcore.foundation.Config` object.\n", |
68 | 68 | "\n", |
69 | 69 | "Read on for more about how these work." |
70 | 70 | ] |
|
189 | 189 | "cell_type": "code", |
190 | 190 | "execution_count": null, |
191 | 191 | "metadata": {}, |
192 | | - "outputs": [], |
| 192 | + "outputs": [ |
| 193 | + { |
| 194 | + "name": "stderr", |
| 195 | + "output_type": "stream", |
| 196 | + "text": [ |
| 197 | + "/Users/jhoward/git/ghapi/ghapi/core.py:99: UserWarning: Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated\n", |
| 198 | + " else: warn('Neither GITHUB_TOKEN nor GITHUB_JWT_TOKEN found: running as unauthenticated')\n" |
| 199 | + ] |
| 200 | + } |
| 201 | + ], |
193 | 202 | "source": [ |
194 | 203 | "#|hide\n", |
195 | 204 | "if os.getenv('GITHUB_ACTIONS') != 'true': # GITHUB_TOKEN in actions has limited scope.\n", |
|
365 | 374 | "cell_type": "markdown", |
366 | 375 | "metadata": {}, |
367 | 376 | "source": [ |
368 | | - "The table above also serves as a full reference of nbdev's settings (excluding the `path` and `cfg_name` parameters which decide where the config file is saved). For more about PyPI classifiers, see [_Classifiers_](https://pypi.org/classifiers/)." |
369 | | - ] |
370 | | - }, |
371 | | - { |
372 | | - "cell_type": "markdown", |
373 | | - "metadata": {}, |
374 | | - "source": [ |
375 | | - "You can create a config file by passing all of the required settings via the command line, as well as any optional settings you'd like to override, for example:" |
376 | | - ] |
377 | | - }, |
378 | | - { |
379 | | - "cell_type": "markdown", |
380 | | - "metadata": {}, |
381 | | - "source": [ |
| 377 | + "The table above also serves as a full reference of nbdev's settings (excluding the `path` and `cfg_name` parameters which decide where the config file is saved). For more about PyPI classifiers, see [_Classifiers_](https://pypi.org/classifiers/).\n", |
| 378 | + "\n", |
| 379 | + "You can create a config file by passing all of the required settings via the command line, as well as any optional settings you'd like to override, for example:\n", |
| 380 | + "\n", |
382 | 381 | "```sh\n", |
383 | 382 | "nbdev_create_config --repo nbdev --user fastai --author fastai \\\n", |
384 | 383 | " --author_email [email protected] --description 'A test project'\n", |
385 | | - "```" |
386 | | - ] |
387 | | - }, |
388 | | - { |
389 | | - "cell_type": "markdown", |
390 | | - "metadata": {}, |
391 | | - "source": [ |
| 384 | + "```\n", |
| 385 | + "\n", |
392 | 386 | "If you don't provide required settings from the command line, we'll try to to infer them from git and GitHub. Finally, you'll be asked to manually input any required settings that we couldn't automatically fill in." |
393 | 387 | ] |
394 | 388 | }, |
|
442 | 436 | "outputs": [], |
443 | 437 | "source": [ |
444 | 438 | "#|export\n", |
| 439 | + "_types = dict(custom_sidebar=bool, nbs_path=Path, lib_path=Path, doc_path=Path, recursive=bool, \n", |
| 440 | + " black_formatting=bool, jupyter_hooks=bool, clean_ids=bool, custom_quarto_yml=bool)\n", |
| 441 | + "\n", |
445 | 442 | "@functools.lru_cache(maxsize=None)\n", |
446 | 443 | "def get_config(cfg_name=_nbdev_cfg_name, path=None):\n", |
447 | 444 | " \"Return nbdev config.\"\n", |
448 | 445 | " cfg_file = _nbdev_config_file(cfg_name, path)\n", |
449 | 446 | " extra_files = _xdg_config_paths(cfg_name)\n", |
450 | | - " cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files)\n", |
| 447 | + " cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files, types=_types)\n", |
451 | 448 | " return _apply_defaults(cfg)" |
452 | 449 | ] |
453 | 450 | }, |
454 | 451 | { |
455 | 452 | "cell_type": "markdown", |
456 | 453 | "metadata": {}, |
457 | 454 | "source": [ |
458 | | - "Searches up from `path` until `cfg_name` is found. User settings are loaded from `~/.config/nbdev/{cfg_name}`. Unspecified optional settings return defaults." |
459 | | - ] |
460 | | - }, |
461 | | - { |
462 | | - "cell_type": "markdown", |
463 | | - "metadata": {}, |
464 | | - "source": [ |
| 455 | + "Searches up from `path` until `cfg_name` is found. User settings are loaded from `~/.config/nbdev/{cfg_name}`. Unspecified optional settings return defaults.\n", |
| 456 | + "\n", |
465 | 457 | "See `nbdev_create_config` for a full reference of nbdev's settings." |
466 | 458 | ] |
467 | 459 | }, |
|
524 | 516 | "cell_type": "markdown", |
525 | 517 | "metadata": {}, |
526 | 518 | "source": [ |
527 | | - "For convenience, use `path` to resolve settings that specify project-relative paths:" |
| 519 | + "Paths are relative to the project:" |
528 | 520 | ] |
529 | 521 | }, |
530 | 522 | { |
|
533 | 525 | "metadata": {}, |
534 | 526 | "outputs": [], |
535 | 527 | "source": [ |
536 | | - "test_eq(cfg.path('doc_path'), p/'_docs')\n", |
537 | | - "test_eq(cfg.path('lib_path'), p/'nbdev')\n", |
538 | | - "test_eq(cfg.path('nbs_path'), p/'nbs')" |
| 528 | + "test_eq(cfg.doc_path, p/'_docs')\n", |
| 529 | + "test_eq(cfg.lib_path, p/'nbdev')\n", |
| 530 | + "test_eq(cfg.nbs_path, p/'nbs')" |
539 | 531 | ] |
540 | 532 | }, |
541 | 533 | { |
|
555 | 547 | " Config('.', 'test_settings.ini', {'repo': 'my-project', 'author': 'fastai', 'nbs_path': 'nbs'});\n", |
556 | 548 | " cfg = get_config('test_settings.ini', '.')\n", |
557 | 549 | " test_eq(cfg.repo, 'my-project')\n", |
558 | | - " test_eq(cfg.lib_path, 'my_project')\n", |
| 550 | + " test_eq(cfg.lib_path.name, 'my_project')\n", |
559 | 551 | " test_eq(cfg.copyright, '2022 ownwards, fastai')" |
560 | 552 | ] |
561 | 553 | }, |
|
573 | 565 | "outputs": [], |
574 | 566 | "source": [ |
575 | 567 | "cfg = get_config('test_settings.ini', '.')\n", |
576 | | - "test_eq(cfg.lib_path, 'nbdev')\n", |
577 | | - "test_eq(cfg.nbs_path, '.')" |
| 568 | + "test_eq(cfg.lib_path, Path('nbdev').resolve())\n", |
| 569 | + "test_eq(cfg.nbs_path, Path('.').resolve())" |
578 | 570 | ] |
579 | 571 | }, |
580 | 572 | { |
|
671 | 663 | "\n", |
672 | 664 | "def update_version(path=None):\n", |
673 | 665 | " \"Add or update `__version__` in the main `__init__.py` of the library.\"\n", |
674 | | - " path = Path(path or get_config().path(\"lib_path\"))\n", |
| 666 | + " path = Path(path or get_config().lib_path)\n", |
675 | 667 | " fname = path/_init\n", |
676 | 668 | " if not fname.exists(): fname.touch()\n", |
677 | 669 | " version = f'__version__ = \"{get_config().version}\"'\n", |
|
685 | 677 | "def add_init(path=None):\n", |
686 | 678 | " \"Add `__init__.py` in all subdirs of `path` containing python files if it's not there already.\"\n", |
687 | 679 | " # we add the lowest-level `__init__.py` files first, which ensures _has_py succeeds for parent modules\n", |
688 | | - " path = Path(path or get_config().path(\"lib_path\"))\n", |
| 680 | + " path = Path(path or get_config().lib_path)\n", |
689 | 681 | " path.mkdir(exist_ok=True)\n", |
690 | 682 | " if not (path/_init).exists(): (path/_init).touch()\n", |
691 | 683 | " for r,ds,fs in os.walk(path, topdown=False):\n", |
|
740 | 732 | "#|export\n", |
741 | 733 | "def _basic_export_nb(fname, name, dest=None):\n", |
742 | 734 | " \"Basic exporter to bootstrap nbdev.\"\n", |
743 | | - " if dest is None: dest = get_config().path('lib_path')\n", |
| 735 | + " if dest is None: dest = get_config().lib_path\n", |
744 | 736 | " add_init()\n", |
745 | 737 | " fname,dest = Path(fname),Path(dest)\n", |
746 | 738 | " nb = read_nb(fname)\n", |
|
0 commit comments