Skip to content

Commit

Permalink
Merge branch 'master' of github.com:deven367/nbdev
Browse files Browse the repository at this point in the history
  • Loading branch information
deven367 committed Dec 1, 2024
2 parents 04fb8f6 + b263f6b commit 3208e39
Show file tree
Hide file tree
Showing 48 changed files with 962 additions and 610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-manual.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to GitHub Pages
name: Deploy to GitHub Pages (Manual)
on:
workflow_dispatch:
jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu, macos]
version: ["3.8", "3.9", "3.10", "3.11"]
version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}-latest
steps:
- uses: fastai/workflows/nbdev-ci@master
with:
version: ${{ matrix.version }}
pre: 1
- name: test docs build
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && matrix.version == '3.9' && matrix.os == 'ubuntu' }}
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch') && matrix.version == '3.10' && matrix.os == 'ubuntu' }}
run: |
set -ux
wget -q $(curl https://latest.fast.ai/pre/quarto-dev/quarto-cli/linux-amd64.deb)
Expand Down
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@

<!-- do not remove -->

## 2.3.31

### New Features

- test if in `nbdev_repo` & improve `nbdev_export` err message ([#1448](https://github.com/fastai/nbdev/pull/1448)), thanks to [@hamelsmu](https://github.com/hamelsmu)


## 2.3.30

### New Features

- add `skip_procs` to `settings.ini` ([#1445](https://github.com/fastai/nbdev/pull/1445)), thanks to [@hamelsmu](https://github.com/hamelsmu)


## 2.3.29

### New Features

- Add `ai_magics` preprocessor ([#1442](https://github.com/fastai/nbdev/issues/1442))


## 2.3.28

### New Features

- Generate module docstrings from markdown meta summary ([#1440](https://github.com/fastai/nbdev/issues/1440))
- By default create markdown versions of docs too ([#1439](https://github.com/fastai/nbdev/issues/1439))
- add markdown to doc output ([#1438](https://github.com/fastai/nbdev/issues/1438))


## 2.3.27

- No new features or fixes---just an update to the pypi status since we forgot about it!

## 2.3.26

### New Features

- add enable/disable cell number in .py files ([#1428](https://github.com/fastai/nbdev/pull/1428)), thanks to [@dienhoa](https://github.com/dienhoa)
- When exporting a notebook to a .py file, we currently have something like `# %% {nb_path} {cell_number}` at the beginning of each exported cell.
- This PR adds one new setting in the setting.ini: `cell_number`. When set to False, we disable the `cell_number` discussed above.
- Side effect: The `cell_number` is used to update the changes from .py back to the notebook, so disabling it also disables this feature.

### Bugs Squashed

- showdoc: SyntaxWarning: invalid escape sequence with Python 3.12 ([#1396](https://github.com/fastai/nbdev/issues/1396))


## 2.3.25

### New Features
Expand Down
2 changes: 1 addition & 1 deletion nbdev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.3.26"
__version__ = "2.3.32"

from .doclinks import nbdev_export
from .showdoc import show_doc
Expand Down
8 changes: 7 additions & 1 deletion nbdev/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
'nbdev.cli._update_repo_meta': ('api/cli.html#_update_repo_meta', 'nbdev/cli.py'),
'nbdev.cli.chelp': ('api/cli.html#chelp', 'nbdev/cli.py'),
'nbdev.cli.extract_tgz': ('api/cli.html#extract_tgz', 'nbdev/cli.py'),
'nbdev.cli.nb_export_cli': ('api/cli.html#nb_export_cli', 'nbdev/cli.py'),
'nbdev.cli.nbdev_filter': ('api/cli.html#nbdev_filter', 'nbdev/cli.py'),
'nbdev.cli.nbdev_new': ('api/cli.html#nbdev_new', 'nbdev/cli.py'),
'nbdev.cli.nbdev_update_license': ('api/cli.html#nbdev_update_license', 'nbdev/cli.py')},
'nbdev.cli.nbdev_update_license': ('api/cli.html#nbdev_update_license', 'nbdev/cli.py'),
'nbdev.cli.watch_export': ('api/cli.html#watch_export', 'nbdev/cli.py')},
'nbdev.config': { 'nbdev.config._apply_defaults': ('api/config.html#_apply_defaults', 'nbdev/config.py'),
'nbdev.config._basic_export_nb': ('api/config.html#_basic_export_nb', 'nbdev/config.py'),
'nbdev.config._cfg2txt': ('api/config.html#_cfg2txt', 'nbdev/config.py'),
Expand All @@ -41,6 +43,7 @@
'nbdev.config.config_key': ('api/config.html#config_key', 'nbdev/config.py'),
'nbdev.config.create_output': ('api/config.html#create_output', 'nbdev/config.py'),
'nbdev.config.get_config': ('api/config.html#get_config', 'nbdev/config.py'),
'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
'nbdev.config.show_src': ('api/config.html#show_src', 'nbdev/config.py'),
'nbdev.config.update_version': ('api/config.html#update_version', 'nbdev/config.py'),
Expand Down Expand Up @@ -71,6 +74,7 @@
'nbdev.doclinks.nbglob_cli': ('api/doclinks.html#nbglob_cli', 'nbdev/doclinks.py'),
'nbdev.doclinks.patch_name': ('api/doclinks.html#patch_name', 'nbdev/doclinks.py')},
'nbdev.export': { 'nbdev.export.ExportModuleProc': ('api/export.html#exportmoduleproc', 'nbdev/export.py'),
'nbdev.export.ExportModuleProc.__call__': ('api/export.html#exportmoduleproc.__call__', 'nbdev/export.py'),
'nbdev.export.ExportModuleProc._default_exp_': ( 'api/export.html#exportmoduleproc._default_exp_',
'nbdev/export.py'),
'nbdev.export.ExportModuleProc._export_': ('api/export.html#exportmoduleproc._export_', 'nbdev/export.py'),
Expand Down Expand Up @@ -203,6 +207,7 @@
'nbdev.processors.add_show_docs': ('api/processors.html#add_show_docs', 'nbdev/processors.py'),
'nbdev.processors.add_show_docs.begin': ( 'api/processors.html#add_show_docs.begin',
'nbdev/processors.py'),
'nbdev.processors.ai_magics': ('api/processors.html#ai_magics', 'nbdev/processors.py'),
'nbdev.processors.boxify': ('api/processors.html#boxify', 'nbdev/processors.py'),
'nbdev.processors.cell_lang': ('api/processors.html#cell_lang', 'nbdev/processors.py'),
'nbdev.processors.clean_magics': ('api/processors.html#clean_magics', 'nbdev/processors.py'),
Expand Down Expand Up @@ -329,6 +334,7 @@
'nbdev.showdoc.ShowDocRenderer': ('api/showdoc.html#showdocrenderer', 'nbdev/showdoc.py'),
'nbdev.showdoc.ShowDocRenderer.__init__': ('api/showdoc.html#showdocrenderer.__init__', 'nbdev/showdoc.py'),
'nbdev.showdoc._bold': ('api/showdoc.html#_bold', 'nbdev/showdoc.py'),
'nbdev.showdoc._create_html_table': ('api/showdoc.html#_create_html_table', 'nbdev/showdoc.py'),
'nbdev.showdoc._docstring': ('api/showdoc.html#_docstring', 'nbdev/showdoc.py'),
'nbdev.showdoc._escape_markdown': ('api/showdoc.html#_escape_markdown', 'nbdev/showdoc.py'),
'nbdev.showdoc._ext_link': ('api/showdoc.html#_ext_link', 'nbdev/showdoc.py'),
Expand Down
32 changes: 17 additions & 15 deletions nbdev/clean.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Strip superfluous metadata from notebooks"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/11_clean.ipynb.

# %% auto 0
__all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'clean_jupyter', 'nbdev_install_hooks']

# %% ../nbs/api/11_clean.ipynb 2
# %% ../nbs/api/11_clean.ipynb
import ast,warnings,stat
from astunparse import unparse
from textwrap import indent
Expand All @@ -18,7 +20,7 @@
from .sync import *
from .process import first_code_ln

# %% ../nbs/api/11_clean.ipynb 6
# %% ../nbs/api/11_clean.ipynb
@call_parse
def nbdev_trust(
fname:str=None, # A notebook name or glob to trust
Expand All @@ -45,7 +47,7 @@ def nbdev_trust(
if not NotebookNotary().check_signature(nb): NotebookNotary().sign(nb)
check_fname.touch(exist_ok=True)

# %% ../nbs/api/11_clean.ipynb 9
# %% ../nbs/api/11_clean.ipynb
_repr_id_re = re.compile('(<.*?)( at 0x[0-9a-fA-F]+)(>)')

_sub = partial(_repr_id_re.sub, r'\1\3')
Expand All @@ -55,7 +57,7 @@ def _skip_or_sub(x): return _sub(x) if "at 0x" in x else x
def _clean_cell_output_id(lines):
return _skip_or_sub(lines) if isinstance(lines,str) else [_skip_or_sub(o) for o in lines]

# %% ../nbs/api/11_clean.ipynb 11
# %% ../nbs/api/11_clean.ipynb
def _clean_cell_output(cell, clean_ids):
"Remove `cell` output execution count and optionally ids from text reprs"
outputs = cell.get('outputs', [])
Expand All @@ -69,7 +71,7 @@ def _clean_cell_output(cell, clean_ids):
if 'text' in o and clean_ids: o['text'] = _clean_cell_output_id(o['text'])
o.get('metadata', {}).pop('tags', None)

# %% ../nbs/api/11_clean.ipynb 12
# %% ../nbs/api/11_clean.ipynb
def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
"Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"
if 'execution_count' in cell: cell['execution_count'] = None
Expand All @@ -80,7 +82,7 @@ def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
cell['metadata'] = {} if clear_all else {
k:v for k,v in cell['metadata'].items() if k in allowed_metadata_keys}

# %% ../nbs/api/11_clean.ipynb 13
# %% ../nbs/api/11_clean.ipynb
def clean_nb(
nb, # The notebook to clean
clear_all=False, # Remove all cell metadata and cell outputs?
Expand All @@ -98,12 +100,12 @@ def clean_nb(
nb['metadata']['kernelspec']['display_name'] = nb["metadata"]["kernelspec"]["name"]
nb['metadata'] = {k:v for k,v in nb['metadata'].items() if k in metadata_keys}

# %% ../nbs/api/11_clean.ipynb 26
# %% ../nbs/api/11_clean.ipynb
def _reconfigure(*strms):
for s in strms:
if hasattr(s,'reconfigure'): s.reconfigure(encoding='utf-8')

# %% ../nbs/api/11_clean.ipynb 27
# %% ../nbs/api/11_clean.ipynb
def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
if not f_out: f_out = f_in
if isinstance(f_in, (str,Path)): f_in = Path(f_in).open(encoding="utf-8")
Expand All @@ -116,7 +118,7 @@ def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
warn(f'{warn_msg}')
warn(e)

# %% ../nbs/api/11_clean.ipynb 28
# %% ../nbs/api/11_clean.ipynb
def _nbdev_clean(nb, path=None, clear_all=None):
cfg = get_config(path=path)
clear_all = clear_all or cfg.clear_all
Expand All @@ -125,7 +127,7 @@ def _nbdev_clean(nb, path=None, clear_all=None):
clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
if path: nbdev_trust.__wrapped__(path)

# %% ../nbs/api/11_clean.ipynb 29
# %% ../nbs/api/11_clean.ipynb
@call_parse
def nbdev_clean(
fname:str=None, # A notebook name or glob to clean
Expand All @@ -141,15 +143,15 @@ def nbdev_clean(
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)

# %% ../nbs/api/11_clean.ipynb 32
# %% ../nbs/api/11_clean.ipynb
def clean_jupyter(path, model, **kwargs):
"Clean Jupyter `model` pre save to `path`"
if not (model['type']=='notebook' and model['content']['nbformat']==4): return
get_config.cache_clear() # Allow config changes without restarting Jupyter
jupyter_hooks = get_config(path=path).jupyter_hooks
if jupyter_hooks: _nbdev_clean(model['content'], path=path)

# %% ../nbs/api/11_clean.ipynb 35
# %% ../nbs/api/11_clean.ipynb
_pre_save_hook_src = '''
def nbdev_clean_jupyter(**kwargs):
try: from nbdev.clean import clean_jupyter
Expand All @@ -159,7 +161,7 @@ def nbdev_clean_jupyter(**kwargs):
c.ContentsManager.pre_save_hook = nbdev_clean_jupyter'''.strip()
_pre_save_hook_re = re.compile(r'c\.(File)?ContentsManager\.pre_save_hook')

# %% ../nbs/api/11_clean.ipynb 36
# %% ../nbs/api/11_clean.ipynb
def _add_jupyter_hooks(src, path):
if _pre_save_hook_src in src: return
mod = ast.parse(src)
Expand All @@ -177,12 +179,12 @@ def _add_jupyter_hooks(src, path):
if src: src+='\n\n'
return src+_pre_save_hook_src

# %% ../nbs/api/11_clean.ipynb 40
# %% ../nbs/api/11_clean.ipynb
def _git_root():
try: return Path(run('git rev-parse --show-toplevel'))
except OSError: return None

# %% ../nbs/api/11_clean.ipynb 43
# %% ../nbs/api/11_clean.ipynb
@call_parse
def nbdev_install_hooks():
"Install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks"
Expand Down
Loading

0 comments on commit 3208e39

Please sign in to comment.