Skip to content

Commit 0f4d622

Browse files
committed
--procs takes * nargs using optional_procs choices
Thank you for the feedback here @jph00. I couldn't quite figure out how to get --procs to work with a tuple. But using Param(.., nargs="*", choices=optional_procs())="black_format" seems to get something more user-friendly for the command line. Here are some examples using `raise Exception(L(procs))` in the method to debug it. ``` > nbdev_export -h usage: nbdev_export [-h] [--path PATH] [--symlinks] [--file_glob FILE_GLOB] [--file_re FILE_RE] [--folder_re FOLDER_RE] [--skip_file_glob SKIP_FILE_GLOB] [--skip_file_re SKIP_FILE_RE] [--skip_folder_re SKIP_FOLDER_RE] [--procs [{black_format,scrub_magics} [{black_format,scrub_magics} ...]]] ... --procs [{black_format,scrub_magics} [{black_format,scrub_magics} ...]] tokens naming the export processors to use. (default: black_format) > nbdev_export Exception: ['black_format'] > nbdev_export --procs > Exception: [] > nbdev_export --procs scrub_magics black_format Exception: ['scrub_magics', 'black_format'] > nbdev_export --procs black_format Exception: ['black_format'] > nbdev_export --procs scrub_magics Exception: ['scrub_magics'] > nbdev_export --procs black_forma usage: nbdev_export [-h] [--path PATH] [--symlinks] [--file_glob FILE_GLOB] [--file_re FILE_RE] [--folder_re FOLDER_RE] [--skip_file_glob SKIP_FILE_GLOB] [--skip_file_re SKIP_FILE_RE] [--skip_folder_re SKIP_FOLDER_RE] [--procs [{black_format,scrub_magics} [{black_format,scrub_magics} ...]]] nbdev_export: error: argument --procs: invalid choice: 'black_forma' (choose from 'black_format', 'scrub_magics') > nbdev_export --procs black_forma scrub_magics usage: nbdev_export [-h] [--path PATH] [--symlinks] [--file_glob FILE_GLOB] [--file_re FILE_RE] [--folder_re FOLDER_RE] [--skip_file_glob SKIP_FILE_GLOB] [--skip_file_re SKIP_FILE_RE] [--skip_folder_re SKIP_FOLDER_RE] [--procs [{black_format,scrub_magics} [{black_format,scrub_magics} ...]]] nbdev_export: error: argument --procs: invalid choice: 'black_forma' (choose from 'black_format', 'scrub_magics') > nbdev_export --procs scrub_magics barst usage: nbdev_export [-h] [--path PATH] [--symlinks] [--file_glob FILE_GLOB] [--file_re FILE_RE] [--folder_re FOLDER_RE] [--skip_file_glob SKIP_FILE_GLOB] [--skip_file_re SKIP_FILE_RE] [--skip_folder_re SKIP_FOLDER_RE] [--procs [{black_format,scrub_magics} [{black_format,scrub_magics} ...]]] nbdev_export: error: argument --procs: invalid choice: 'barst' (choose from 'black_format', 'scrub_magics') ```
1 parent ca1d792 commit 0f4d622

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

nbdev/doclinks.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,17 @@ def nbglob_cli(
127127
skip_file_glob=skip_file_glob, skip_file_re=skip_file_re, skip_folder_re=skip_folder_re)
128128

129129
# %% ../nbs/api/05_doclinks.ipynb 22
130-
# the import is needed to call getattr on it
131-
import nbdev.export
132-
133130
@call_parse
134131
@delegates(nbglob_cli)
135132
def nbdev_export(
136133
path:str=None, # Path or filename
137-
procs:str="black_format", # whitespace delimited tokens of processors to use.
134+
procs:Param("tokens naming the export processors to use.", nargs="*", choices=optional_procs())="black_format",
138135
**kwargs):
139136
"Export notebooks in `path` to Python modules"
140137
if os.environ.get('IN_TEST',0): return
141-
if procs: procs = [getattr(nbdev.export, p) for p in procs.split(" ") if p in optional_procs()]
138+
if procs:
139+
import nbdev.export
140+
procs = [getattr(nbdev.export, p) for p in L(procs)]
142141
files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
143142
for f in files: nb_export(f, procs=procs)
144143
add_init(get_config().lib_path)

nbs/api/05_doclinks.ipynb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,18 @@
347347
"outputs": [],
348348
"source": [
349349
"#|export\n",
350-
"# the import is needed to call getattr on it\n",
351-
"import nbdev.export\n",
352350
"\n",
353351
"@call_parse\n",
354352
"@delegates(nbglob_cli)\n",
355353
"def nbdev_export(\n",
356354
" path:str=None, # Path or filename\n",
357-
" procs:str=\"black_format\", # whitespace delimited tokens of processors to use.\n",
355+
" procs:Param(\"tokens naming the export processors to use.\", nargs=\"*\", choices=optional_procs())=\"black_format\",\n",
358356
" **kwargs):\n",
359357
" \"Export notebooks in `path` to Python modules\"\n",
360358
" if os.environ.get('IN_TEST',0): return\n",
361-
" if procs: procs = [getattr(nbdev.export, p) for p in procs.split(\" \") if p in optional_procs()]\n",
359+
" if procs:\n",
360+
" import nbdev.export\n",
361+
" procs = [getattr(nbdev.export, p) for p in L(procs)]\n",
362362
" files = nbglob(path=path, as_path=True, **kwargs).sorted('name')\n",
363363
" for f in files: nb_export(f, procs=procs)\n",
364364
" add_init(get_config().lib_path)\n",
@@ -369,10 +369,9 @@
369369
"cell_type": "markdown",
370370
"metadata": {},
371371
"source": [
372-
"`procs` takes the names of any optional processors you with to run on the exported cells of your notebook.\n",
373-
"It can be a list of processors\n",
372+
"`procs` names the optional processors you wish to run on the exported cells of your notebook.\n",
374373
"\n",
375-
"N.B.: the `black_format` processor is passed in by default. But it is a no-op, unless `black_formatting=True` is set in your `settings.ini` configuration."
374+
"N.B.: the `black_format` processor is passed in by default. But it is a no-op, unless `black_formatting=True` is set in your `settings.ini` configuration. You can omit it from `nbdev_export` on the command line by passing in `--procs`."
376375
]
377376
},
378377
{

0 commit comments

Comments
 (0)