Skip to content

Commit

Permalink
move nbdev detection to fastcore
Browse files Browse the repository at this point in the history
  • Loading branch information
hamelsmu committed Sep 18, 2024
1 parent de52343 commit 39f4fc2
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fastcore/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
24 changes: 24 additions & 0 deletions fastcore/nbdev.py
Original file line number Diff line number Diff line change
@@ -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()
124 changes: 124 additions & 0 deletions nbs/13_nbdev.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 39f4fc2

Please sign in to comment.