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

fix #1041 #1049

Merged
merged 2 commits into from
Sep 14, 2022
Merged
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
1 change: 1 addition & 0 deletions nbdev/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'nbdev.config._has_py': ('api/config.html#_has_py', 'nbdev/config.py'),
'nbdev.config._nbdev_config_file': ('api/config.html#_nbdev_config_file', 'nbdev/config.py'),
'nbdev.config._prompt_user': ('api/config.html#_prompt_user', 'nbdev/config.py'),
'nbdev.config._type': ('api/config.html#_type', 'nbdev/config.py'),
'nbdev.config._xdg_config_paths': ('api/config.html#_xdg_config_paths', 'nbdev/config.py'),
'nbdev.config.add_init': ('api/config.html#add_init', 'nbdev/config.py'),
'nbdev.config.config_key': ('api/config.html#config_key', 'nbdev/config.py'),
Expand Down
12 changes: 5 additions & 7 deletions nbdev/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
# %% ../nbs/api/clean.ipynb 13
def clean_nb(
nb, # The notebook to clean
clear_all=False, # Remove all cell metadata and cell outputs
clear_all=False, # Remove all cell metadata and cell outputs?
Copy link
Member

Choose a reason for hiding this comment

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

Do you think the question mark could be confusing? It is a bit confusing for me

Meaning I interpret it as we aren't sure what the program will do

Copy link
Member Author

Choose a reason for hiding this comment

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

It's something I noticed Jeremy doing to describe bool parameters and quite liked myself. I think you get used to reading the ? as not sounding confused 😄

Copy link
Member

Choose a reason for hiding this comment

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

haha ok

allowed_metadata_keys:list=None, # Preserve the list of keys in the main notebook metadata
allowed_cell_metadata_keys:list=None, # Preserve the list of keys in cell level metadata
clean_ids=True, # Remove ids from plaintext reprs?
Expand Down Expand Up @@ -113,19 +113,18 @@ def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
warn(e)

# %% ../nbs/api/clean.ipynb 26
def _nbdev_clean(nb, path=None, **kwargs):
def _nbdev_clean(nb, path=None, clear_all=None):
cfg = get_config(path=path)
clear_all = clear_all or cfg.clear_all
allowed_metadata_keys = cfg.get("allowed_metadata_keys").split()
allowed_cell_metadata_keys = cfg.get("allowed_cell_metadata_keys").split()
clean_ids = cfg.get('clean_ids', False)
return clean_nb(nb, clean_ids=clean_ids, allowed_metadata_keys=allowed_metadata_keys,
allowed_cell_metadata_keys=allowed_cell_metadata_keys, **kwargs)
return clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)

# %% ../nbs/api/clean.ipynb 27
@call_parse
def nbdev_clean(
fname:str=None, # A notebook name or glob to clean
clear_all:bool=False, # Clean all metadata and outputs
clear_all:bool=False, # Remove all cell metadata and cell outputs?
disp:bool=False, # Print the cleaned outputs
stdin:bool=False # Read notebook from input stream
):
Expand All @@ -134,7 +133,6 @@ def nbdev_clean(
_clean = partial(_nbdev_clean, clear_all=clear_all)
_write = partial(process_write, warn_msg='Failed to clean notebook', proc_nb=_clean)
if stdin: return _write(f_in=sys.stdin, f_out=sys.stdout)

if fname is None: fname = get_config().nbs_path
for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)

Expand Down
12 changes: 7 additions & 5 deletions nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# %% ../nbs/api/config.ipynb 4
from datetime import datetime
from fastcore.docments import *
from fastcore.utils import *
from fastcore.meta import *
from fastcore.script import *
Expand Down Expand Up @@ -40,9 +41,9 @@ def _apply_defaults(
branch='master', # Repo default branch
git_url='https:/%(user)s/%(repo)s', # Repo URL
custom_sidebar:bool_arg=False, # Use a custom sidebar.yml?
nbs_path='.', # Path to notebooks
lib_path:str=None, # Path to package root (default: `repo` with `-` replaced by `_`)
doc_path='_docs', # Path to rendered docs
nbs_path:Path='.', # Path to notebooks
lib_path:Path=None, # Path to package root (default: `repo` with `-` replaced by `_`)
doc_path:Path='_docs', # Path to rendered docs
tst_flags='notest', # Test flags
version='0.0.1', # Version of this release
doc_host='https://%(user)s.github.io', # Hostname for docs
Expand All @@ -62,6 +63,7 @@ def _apply_defaults(
allowed_cell_metadata_keys='', # Preserve the list of keys in cell level metadata
jupyter_hooks=True, # Run Jupyter hooks?
clean_ids=True, # Remove ids from plaintext reprs?
clear_all=False, # Remove all cell metadata and cell outputs?
custom_quarto_yml=False, # Use a custom _quarto.yml?
):
"Apply default settings where missing in `cfg`."
Expand Down Expand Up @@ -188,8 +190,8 @@ def _xdg_config_paths(cfg_name=_nbdev_cfg_name):
return [o/_nbdev_home_dir/cfg_name for o in xdg_config_paths]

# %% ../nbs/api/config.ipynb 28
_types = dict(custom_sidebar=bool, nbs_path=Path, lib_path=Path, doc_path=Path, recursive=bool,
black_formatting=bool, jupyter_hooks=bool, clean_ids=bool, custom_quarto_yml=bool, preview_port=int)
def _type(t): return bool if t==bool_arg else t
_types = {k:_type(v['anno']) for k,v in docments(_apply_defaults,full=True,returns=False).items() if k != 'cfg'}

@functools.lru_cache(maxsize=None)
def get_config(cfg_name=_nbdev_cfg_name, path=None):
Expand Down
16 changes: 6 additions & 10 deletions nbs/api/clean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide_input": false
},
"metadata": {},
"outputs": [],
"source": [
"#|default_exp clean"
Expand Down Expand Up @@ -191,7 +189,7 @@
"#|export\n",
"def clean_nb(\n",
" nb, # The notebook to clean\n",
" clear_all=False, # Remove all cell metadata and cell outputs\n",
" clear_all=False, # Remove all cell metadata and cell outputs?\n",
" allowed_metadata_keys:list=None, # Preserve the list of keys in the main notebook metadata\n",
" allowed_cell_metadata_keys:list=None, # Preserve the list of keys in cell level metadata\n",
" clean_ids=True, # Remove ids from plaintext reprs?\n",
Expand Down Expand Up @@ -348,13 +346,12 @@
"outputs": [],
"source": [
"#|export\n",
"def _nbdev_clean(nb, path=None, **kwargs):\n",
"def _nbdev_clean(nb, path=None, clear_all=None):\n",
" cfg = get_config(path=path)\n",
" clear_all = clear_all or cfg.clear_all\n",
" allowed_metadata_keys = cfg.get(\"allowed_metadata_keys\").split()\n",
" allowed_cell_metadata_keys = cfg.get(\"allowed_cell_metadata_keys\").split()\n",
" clean_ids = cfg.get('clean_ids', False)\n",
" return clean_nb(nb, clean_ids=clean_ids, allowed_metadata_keys=allowed_metadata_keys,\n",
" allowed_cell_metadata_keys=allowed_cell_metadata_keys, **kwargs)"
" return clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)"
]
},
{
Expand All @@ -367,7 +364,7 @@
"@call_parse\n",
"def nbdev_clean(\n",
" fname:str=None, # A notebook name or glob to clean\n",
" clear_all:bool=False, # Clean all metadata and outputs\n",
" clear_all:bool=False, # Remove all cell metadata and cell outputs?\n",
" disp:bool=False, # Print the cleaned outputs\n",
" stdin:bool=False # Read notebook from input stream\n",
"):\n",
Expand All @@ -376,7 +373,6 @@
" _clean = partial(_nbdev_clean, clear_all=clear_all)\n",
" _write = partial(process_write, warn_msg='Failed to clean notebook', proc_nb=_clean)\n",
" if stdin: return _write(f_in=sys.stdin, f_out=sys.stdout)\n",
" \n",
" if fname is None: fname = get_config().nbs_path\n",
" for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)"
]
Expand Down
14 changes: 8 additions & 6 deletions nbs/api/config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"source": [
"#|export\n",
"from datetime import datetime\n",
"from fastcore.docments import *\n",
"from fastcore.utils import *\n",
"from fastcore.meta import *\n",
"from fastcore.script import *\n",
Expand Down Expand Up @@ -148,9 +149,9 @@
" branch='master', # Repo default branch\n",
" git_url='https:/%(user)s/%(repo)s', # Repo URL\n",
" custom_sidebar:bool_arg=False, # Use a custom sidebar.yml?\n",
" nbs_path='.', # Path to notebooks\n",
" lib_path:str=None, # Path to package root (default: `repo` with `-` replaced by `_`)\n",
" doc_path='_docs', # Path to rendered docs\n",
" nbs_path:Path='.', # Path to notebooks\n",
" lib_path:Path=None, # Path to package root (default: `repo` with `-` replaced by `_`)\n",
" doc_path:Path='_docs', # Path to rendered docs\n",
" tst_flags='notest', # Test flags\n",
" version='0.0.1', # Version of this release\n",
" doc_host='https://%(user)s.github.io', # Hostname for docs\n",
Expand All @@ -170,6 +171,7 @@
" allowed_cell_metadata_keys='', # Preserve the list of keys in cell level metadata\n",
" jupyter_hooks=True, # Run Jupyter hooks?\n",
" clean_ids=True, # Remove ids from plaintext reprs?\n",
" clear_all=False, # Remove all cell metadata and cell outputs?\n",
" custom_quarto_yml=False, # Use a custom _quarto.yml?\n",
"):\n",
" \"Apply default settings where missing in `cfg`.\"\n",
Expand Down Expand Up @@ -451,8 +453,8 @@
"outputs": [],
"source": [
"#|export\n",
"_types = dict(custom_sidebar=bool, nbs_path=Path, lib_path=Path, doc_path=Path, recursive=bool, \n",
" black_formatting=bool, jupyter_hooks=bool, clean_ids=bool, custom_quarto_yml=bool, preview_port=int)\n",
"def _type(t): return bool if t==bool_arg else t\n",
"_types = {k:_type(v['anno']) for k,v in docments(_apply_defaults,full=True,returns=False).items() if k != 'cfg'}\n",
"\n",
"@functools.lru_cache(maxsize=None)\n",
"def get_config(cfg_name=_nbdev_cfg_name, path=None):\n",
Expand Down Expand Up @@ -785,7 +787,7 @@
"path = Path('../nbdev')\n",
"(path/'config.py').unlink(missing_ok=True)\n",
"\n",
"_basic_export_nb(\"01_config.ipynb\", 'config.py')\n",
"_basic_export_nb(\"config.ipynb\", 'config.py')\n",
"\n",
"g = exec_new('from nbdev import config')\n",
"assert g['config'].add_init\n",
Expand Down
1 change: 1 addition & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ allowed_cell_metadata_keys =
jupyter_hooks = True
clean_ids = False
custom_quarto_yml = True
clear_all = False