Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move nbdev detection to fastcore #627

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would normally make this a one-liner, but I think having a a docstring is good for LLMs?

"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
}
Loading