diff --git a/fastcore/_modidx.py b/fastcore/_modidx.py index 3d86c296..39d1ab42 100644 --- a/fastcore/_modidx.py +++ b/fastcore/_modidx.py @@ -392,6 +392,8 @@ 'fastcore.meta.use_kwargs': ('meta.html#use_kwargs', 'fastcore/meta.py'), 'fastcore.meta.use_kwargs_dict': ('meta.html#use_kwargs_dict', 'fastcore/meta.py')}, 'fastcore.nb_imports': {}, + 'fastcore.nbdev': { 'fastcore.nbdev.is_nbdev': ('nbdev.html#is_nbdev', 'fastcore/nbdev.py'), + 'fastcore.nbdev.nbdev_config_file': ('nbdev.html#nbdev_config_file', 'fastcore/nbdev.py')}, 'fastcore.net': { 'fastcore.net.HTTP4xxClientError': ('net.html#http4xxclienterror', 'fastcore/net.py'), 'fastcore.net.HTTP5xxServerError': ('net.html#http5xxservererror', 'fastcore/net.py'), 'fastcore.net.Request.summary': ('net.html#request.summary', 'fastcore/net.py'), diff --git a/fastcore/nbdev.py b/fastcore/nbdev.py new file mode 100644 index 00000000..cec60b1e --- /dev/null +++ b/fastcore/nbdev.py @@ -0,0 +1,24 @@ +"""Utilities for the nbdev library.""" + +# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/13_nbdev.ipynb. + +# %% auto 0 +__all__ = ['nbdev_config_file', 'is_nbdev'] + +# %% ../nbs/13_nbdev.ipynb +from .basics import Path + +# %% ../nbs/13_nbdev.ipynb +_nbdev_cfg_name = 'settings.ini' + +def nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None): + "Get the nbdev config file path" + cfg_path = path = Path.cwd() if path is None else Path(path) + while cfg_path != cfg_path.parent and not (cfg_path/cfg_name).exists(): cfg_path = cfg_path.parent + if not (cfg_path/cfg_name).exists(): cfg_path = path + return cfg_path/cfg_name + +# %% ../nbs/13_nbdev.ipynb +def is_nbdev(): + "Checks if the current directory is in a nbdev project." + return nbdev_config_file().exists() diff --git a/nbs/13_nbdev.ipynb b/nbs/13_nbdev.ipynb new file mode 100644 index 00000000..987f3b3a --- /dev/null +++ b/nbs/13_nbdev.ipynb @@ -0,0 +1,124 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7bea0d2f", + "metadata": {}, + "source": [ + "# nbdev utilities\n", + "> Utilities for the nbdev library." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "07a035a5", + "metadata": {}, + "outputs": [], + "source": [ + "#|default_exp nbdev" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "75e11db6", + "metadata": {}, + "outputs": [], + "source": [ + "#|export\n", + "from fastcore.basics import Path" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "558b4d4c", + "metadata": {}, + "outputs": [], + "source": [ + "#|hide\n", + "from nbdev.export import *\n", + "from fastcore.test import *" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "da2ac196", + "metadata": {}, + "outputs": [], + "source": [ + "#|export\n", + "_nbdev_cfg_name = 'settings.ini'\n", + "\n", + "def nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None):\n", + " \"Get the nbdev config file path\"\n", + " cfg_path = path = Path.cwd() if path is None else Path(path)\n", + " while cfg_path != cfg_path.parent and not (cfg_path/cfg_name).exists(): cfg_path = cfg_path.parent\n", + " if not (cfg_path/cfg_name).exists(): cfg_path = path\n", + " return cfg_path/cfg_name" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c44a414", + "metadata": {}, + "outputs": [], + "source": [ + "#|export\n", + "def is_nbdev(): \n", + " \"Checks if the current directory is in a nbdev project.\"\n", + " return nbdev_config_file().exists()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "604a2243", + "metadata": {}, + "outputs": [], + "source": [ + "#|hide\n", + "test_eq(is_nbdev(), True)" + ] + }, + { + "cell_type": "markdown", + "id": "df973d4e", + "metadata": {}, + "source": [ + "# Export -" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "914d16ca", + "metadata": {}, + "outputs": [], + "source": [ + "#|hide\n", + "import nbdev; nbdev.nbdev_export()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20a20020", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "python3", + "language": "python", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}