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

Better handling of cells that contain string 'nbdev_export(' #1490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions nbdev/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ def _ast_contains(trees, types):

def _do_eval(cell):
if cell_lang(cell) != 'python': return
if not cell.source or 'nbdev_export'+'()' in cell.source: return
if not cell.source: return
trees = cell.parsed_()
if cell.cell_type != 'code' or not trees: return
if cell.directives_.get('eval:', [''])[0].lower() == 'false': return

_show_dirs = {'export','exports','exporti','exec_doc'}
if cell.directives_.keys() & _show_dirs: return True
if _ast_contains(trees, (ast.Import, ast.ImportFrom)):
if _ast_contains(trees, (ast.Expr, ast.Assign)):
if _ast_contains(trees, (ast.Expr, ast.Assign)) and 'nbdev_export' not in cell.source:
warn(f'Found cells containing imports and other code. See FAQ.\n---\n{cell.source}\n---\n')
return True
if _show_docs(trees): return True
Expand Down
1 change: 0 additions & 1 deletion nbdev/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_nb(fn, # file name of notebook to test

def _no_eval(cell):
if cell.cell_type != 'code': return True
if 'nbdev_export'+'(' in cell.source: return True
direc = getattr(cell, 'directives_', {}) or {}
if direc.get('eval:', [''])[0].lower() == 'false': return True
return flags & direc.keys()
Expand Down
4 changes: 2 additions & 2 deletions nbs/api/10_processors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -683,15 +683,15 @@
"\n",
"def _do_eval(cell):\n",
" if cell_lang(cell) != 'python': return\n",
" if not cell.source or 'nbdev_export'+'()' in cell.source: return\n",
" if not cell.source: return\n",
" trees = cell.parsed_()\n",
" if cell.cell_type != 'code' or not trees: return\n",
" if cell.directives_.get('eval:', [''])[0].lower() == 'false': return\n",
"\n",
" _show_dirs = {'export','exports','exporti','exec_doc'}\n",
" if cell.directives_.keys() & _show_dirs: return True\n",
" if _ast_contains(trees, (ast.Import, ast.ImportFrom)):\n",
" if _ast_contains(trees, (ast.Expr, ast.Assign)):\n",
" if _ast_contains(trees, (ast.Expr, ast.Assign)) and 'nbdev_export' not in cell.source:\n",
" warn(f'Found cells containing imports and other code. See FAQ.\\n---\\n{cell.source}\\n---\\n')\n",
" return True\n",
" if _show_docs(trees): return True"
Expand Down
1 change: 0 additions & 1 deletion nbs/api/12_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"\n",
" def _no_eval(cell):\n",
" if cell.cell_type != 'code': return True\n",
" if 'nbdev_export'+'(' in cell.source: return True\n",
" direc = getattr(cell, 'directives_', {}) or {}\n",
" if direc.get('eval:', [''])[0].lower() == 'false': return True\n",
" return flags & direc.keys()\n",
Expand Down