nbdev 2.3.23__py3-none-any.whl → 2.3.26__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nbdev/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "2.3.23"
1
+ __version__ = "2.3.26"
2
2
 
3
3
  from .doclinks import nbdev_export
4
4
  from .showdoc import show_doc
nbdev/clean.py CHANGED
@@ -30,6 +30,7 @@ def nbdev_trust(
30
30
  import warnings
31
31
  warnings.warn("Please install jupyter and try again")
32
32
  return
33
+ from nbformat import read
33
34
 
34
35
  fname = Path(fname if fname else get_config().nbs_path)
35
36
  path = fname if fname.is_dir() else fname.parent
@@ -40,7 +41,7 @@ def nbdev_trust(
40
41
  if last_checked and not force_all:
41
42
  last_changed = os.path.getmtime(fn)
42
43
  if last_changed < last_checked: continue
43
- nb = read_nb(fn)
44
+ with open(fn, 'r', encoding='utf-8') as f: nb = read(f, as_version=4)
44
45
  if not NotebookNotary().check_signature(nb): NotebookNotary().sign(nb)
45
46
  check_fname.touch(exist_ok=True)
46
47
 
@@ -121,7 +122,8 @@ def _nbdev_clean(nb, path=None, clear_all=None):
121
122
  clear_all = clear_all or cfg.clear_all
122
123
  allowed_metadata_keys = cfg.get("allowed_metadata_keys").split()
123
124
  allowed_cell_metadata_keys = cfg.get("allowed_cell_metadata_keys").split()
124
- return clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
125
+ clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
126
+ if path: nbdev_trust.__wrapped__(path)
125
127
 
126
128
  # %% ../nbs/api/11_clean.ipynb 29
127
129
  @call_parse
nbdev/config.py CHANGED
@@ -66,6 +66,7 @@ def _apply_defaults(
66
66
  jupyter_hooks:bool_arg=False, # Run Jupyter hooks?
67
67
  clean_ids:bool_arg=True, # Remove ids from plaintext reprs?
68
68
  clear_all:bool_arg=False, # Remove all cell metadata and cell outputs?
69
+ cell_number:bool_arg=True, # Add cell number to the exported file
69
70
  put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export
70
71
  ):
71
72
  "Apply default settings where missing in `cfg`."
@@ -222,7 +223,7 @@ def create_output(txt, mime):
222
223
  def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
223
224
 
224
225
  # %% ../nbs/api/01_config.ipynb 48
225
- _re_version = re.compile('^__version__\s*=.*$', re.MULTILINE)
226
+ _re_version = re.compile(r'^__version__\s*=.*$', re.MULTILINE)
226
227
  _init = '__init__.py'
227
228
 
228
229
  def update_version(path=None):
@@ -251,10 +252,12 @@ def add_init(path=None):
251
252
  if get_config().get('put_version_in_init', True): update_version(path)
252
253
 
253
254
  # %% ../nbs/api/01_config.ipynb 51
254
- def write_cells(cells, hdr, file, offset=0):
255
+ def write_cells(cells, hdr, file, offset=0, cell_number=True):
255
256
  "Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
256
257
  for cell in cells:
257
- if cell.source.strip(): file.write(f'\n\n{hdr} {cell.idx_+offset}\n{cell.source}')
258
+ if cell.source.strip():
259
+ idx = f" {cell.idx_+offset}" if cell_number else ""
260
+ file.write(f'\n\n{hdr}{idx}\n{cell.source}')
258
261
 
259
262
  # %% ../nbs/api/01_config.ipynb 52
260
263
  def _basic_export_nb(fname, name, dest=None):
nbdev/doclinks.py CHANGED
@@ -47,16 +47,22 @@ def _iter_py_cells(p):
47
47
  "Yield cells from an exported Python file."
48
48
  p = Path(p)
49
49
  cells = p.read_text(encoding='utf-8').split("\n# %% ")
50
+ has_cell_number = get_config().cell_number
50
51
  for cell in cells[1:]:
51
52
  top,code = cell.split('\n', 1)
52
53
  try:
53
- *nb,idx = top.split()
54
- nb = ' '.join(nb)
54
+ if has_cell_number:
55
+ *nb,idx = top.split()
56
+ nb = ' '.join(nb)
57
+ idx = int(idx)
58
+ else:
59
+ nb = top
60
+ idx = None
55
61
  except ValueError: raise ValueError(f"Unexpected format in '{p}' at cell:\n```\n# %% {cell.strip()}.\n```\n"
56
62
  "The expected format is: '# %% {nb_path} {cell_idx}'.")
57
63
  nb_path = None if nb=='auto' else (p.parent/nb).resolve() # NB paths are stored relative to .py file
58
64
  if code.endswith('\n'): code=code[:-1]
59
- yield AttrDict(nb=nb, idx=int(idx), code=code, nb_path=nb_path, py_path=p.resolve())
65
+ yield AttrDict(nb=nb, idx=idx, code=code, nb_path=nb_path, py_path=p.resolve())
60
66
 
61
67
  # %% ../nbs/api/05_doclinks.ipynb 11
62
68
  def _nbpath2html(p): return p.with_name(re.sub(r'^\d+[a-zA-Z0-9]*_', '', p.name.lower())).with_suffix('.html')
@@ -71,7 +77,7 @@ def _get_modidx(py_path, code_root, nbs_path):
71
77
  _def_types = ast.FunctionDef,ast.AsyncFunctionDef,ast.ClassDef
72
78
  d = {}
73
79
  for cell in _iter_py_cells(py_path):
74
- if cell.nb == 'auto': continue
80
+ if 'auto' in cell.nb: continue
75
81
  loc = _nbpath2html(cell.nb_path.relative_to(nbs_path))
76
82
 
77
83
  def _stor(nm):
@@ -98,7 +104,7 @@ def _build_modidx(dest=None, nbs_path=None, skip_exists=False):
98
104
  res['settings'] = {k:v for k,v in get_config().d.items()
99
105
  if k in ('doc_host','doc_baseurl','lib_path','git_url','branch')}
100
106
  code_root = dest.parent.resolve()
101
- for file in globtastic(dest, file_glob="*.py", skip_file_re='^_', skip_folder_re="\.ipynb_checkpoints"):
107
+ for file in globtastic(dest, file_glob="*.py", skip_file_re='^_', skip_folder_re=r"\.ipynb_checkpoints"):
102
108
  res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))
103
109
  idxfile.write_text("# Autogenerated by nbdev\n\nd = "+pformat(res, width=140, indent=2, compact=True)+'\n')
104
110
 
nbdev/maker.py CHANGED
@@ -207,7 +207,7 @@ def make(self:ModuleMaker, cells, all_cells=None, lib_path=None):
207
207
  f.write(f"# AUTOGENERATED! DO NOT EDIT! File to edit: {self.dest2nb}.")
208
208
  if last_future > 0: write_cells(cells[:last_future], self.hdr, f)
209
209
  if self.parse: f.write(f"\n\n# %% auto 0\n__all__ = {all_str}")
210
- write_cells(cells[last_future:], self.hdr, f)
210
+ write_cells(cells[last_future:], self.hdr, f, cell_number=get_config().cell_number)
211
211
  f.write('\n')
212
212
 
213
213
  # %% ../nbs/api/02_maker.ipynb 38
nbdev/quarto.py CHANGED
@@ -68,7 +68,7 @@ def _sort(a):
68
68
  if y.startswith('index.'): return x,'00'
69
69
  return a
70
70
  #|export
71
- _def_file_re = '\.(?:ipynb|qmd|html)$'
71
+ _def_file_re = r'\.(?:ipynb|qmd|html)$'
72
72
 
73
73
  @delegates(nbglob_cli)
74
74
  def _nbglob_docs(
@@ -87,12 +87,12 @@ def _recursive_parser(
87
87
  set_index: bool = True): # If `True`, `index` file will be set to href.
88
88
  for name, val in dir_dict.items():
89
89
  if type(val) is str:
90
- if re.search('index\..*', re.sub('^\d+_', '', val)) and set_index and section:
90
+ if re.search('index\..*', re.sub(r'^\d+_', '', val)) and set_index and section:
91
91
  section.update({'href': str(dirpath/val)})
92
92
  else:
93
93
  contents.append(str(dirpath/val))
94
94
  elif type(val) is dict:
95
- name = re.sub('^\d+_', '', name)
95
+ name = re.sub(r'^\d+_', '', name)
96
96
  section = {'section': name, 'contents': []}
97
97
  contents.append(section)
98
98
  _recursive_parser(val, section['contents'], dirpath/name, section=section)
nbdev/release.py CHANGED
@@ -240,11 +240,11 @@ def write_conda_meta(path='conda'):
240
240
  _write_yaml(path, *_get_conda_meta())
241
241
 
242
242
  # %% ../nbs/api/18_release.ipynb 43
243
- # This function is used as a utility for creating HF spaces.
244
- def write_requirements(directory=None):
243
+ @call_parse
244
+ def write_requirements(path:str=''):
245
245
  "Writes a `requirements.txt` file to `directory` based on settings.ini."
246
246
  cfg = get_config()
247
- d = Path(directory) if directory else cfg.config_path
247
+ d = Path(path) if path else cfg.config_path
248
248
  req = '\n'.join([cfg.get(k, '').replace(' ', '\n') for k in ['requirements', 'pip_requirements']])
249
249
  (d/'requirements.txt').mk_write(req)
250
250
 
nbdev/showdoc.py CHANGED
@@ -25,7 +25,7 @@ def _bold(s): return f'**{s}**' if s.strip() else s
25
25
 
26
26
  # %% ../nbs/api/08_showdoc.ipynb 7
27
27
  def _escape_markdown(s):
28
- for c in '|^': s = re.sub(rf'\\?\{c}', f'\{c}', s)
28
+ for c in '|^': s = re.sub(rf'\\?\{c}', rf'\{c}', s)
29
29
  return s.replace('\n', '<br>')
30
30
 
31
31
  # %% ../nbs/api/08_showdoc.ipynb 9
nbdev/sync.py CHANGED
@@ -34,7 +34,7 @@ def _mod_files():
34
34
  return L(files for mod in midx.d['syms'].values() for _,files in mod.values()).unique()
35
35
 
36
36
  # %% ../nbs/api/06_sync.ipynb 8
37
- _re_import = re.compile("from\s+\S+\s+import\s+\S")
37
+ _re_import = re.compile(r"from\s+\S+\s+import\s+\S")
38
38
 
39
39
  # %% ../nbs/api/06_sync.ipynb 10
40
40
  def _to_absolute(code, py_path, lib_dir):
@@ -67,6 +67,7 @@ def nbdev_update(fname:str=None): # A Python file name to update
67
67
  if fname and fname.endswith('.ipynb'): raise ValueError("`nbdev_update` operates on .py files. If you wish to convert notebooks instead, see `nbdev_export`.")
68
68
  if os.environ.get('IN_TEST',0): return
69
69
  cfg = get_config()
70
+ if not cfg.cell_number: raise ValueError("`nbdev_update` does not support without cell_number in .py files. Please check your settings.ini")
70
71
  fname = Path(fname or cfg.lib_path)
71
72
  lib_dir = cfg.lib_path.parent
72
73
  files = globtastic(fname, file_glob='*.py', skip_folder_re='^[_.]').filter(lambda x: str(Path(x).absolute().relative_to(lib_dir) in _mod_files()))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nbdev
3
- Version: 2.3.23
3
+ Version: 2.3.26
4
4
  Summary: Create delightful software with Jupyter Notebooks
5
5
  Home-page: https://github.com/fastai/nbdev
6
6
  Author: Jeremy Howard and Hamel Husain
@@ -143,10 +143,12 @@ available commands:
143
143
  nbdev_release_both Release both conda and PyPI packages
144
144
  nbdev_release_gh Calls `nbdev_changelog`, lets you edit the result, then pushes to git and calls `nbdev_release_git`
145
145
  nbdev_release_git Tag and create a release in GitHub for the current version
146
+ nbdev_requirements Writes a `requirements.txt` file to `directory` based on settings.ini.
146
147
  nbdev_sidebar Create sidebar.yml
147
148
  nbdev_test Test in parallel notebooks matching `path`, passing along `flags`
148
149
  nbdev_trust Trust notebooks matching `fname`
149
150
  nbdev_update Propagate change in modules matching `fname` to notebooks that created them
151
+ nbdev_update_license Allows you to update the license of your project.
150
152
 
151
153
  ## FAQ
152
154
 
@@ -1,29 +1,29 @@
1
- nbdev/__init__.py,sha256=3fHAHcA_BTXmByVi4y4h51YHZ1ncErSQeTNZxw1-fBM,90
1
+ nbdev/__init__.py,sha256=P9VMWkWqJEua4n5Tu90cHCgvYUZEs9x3z4dHMMiCs4U,90
2
2
  nbdev/_modidx.py,sha256=cfvhKryWwys106hchXzhcUqC37lQHHAKJKk6vrUiRAs,40317
3
- nbdev/clean.py,sha256=lLtfhCLjkDBqf8MvIG9lDSWSmA9vUDvn2QhS6LPprHI,9284
3
+ nbdev/clean.py,sha256=RLhM4-joJNpxauTy33HYb3gaUHaKtCOaWfrKWec5Zd4,9403
4
4
  nbdev/cli.py,sha256=OAEdAqGdgHbUFYjHmn8ZmFNbBCxJjwvtDwgYatjmh1U,5639
5
- nbdev/config.py,sha256=2WrrWR_3kyxUEmzz7hliVWDlYzWkLlOsiL08tUopNnI,12236
6
- nbdev/doclinks.py,sha256=X5d8Xz52p-LlWwhhCN6d-00RQ0E8BsONuPH_xUSA6kc,10287
5
+ nbdev/config.py,sha256=CdaimA7eSdWHYYw7q07QA5j4q_pzMyOhG0BRHw3D2Qk,12387
6
+ nbdev/doclinks.py,sha256=zqhEyOXFBfGNZ6HSIQihwofoLzxjgGqzikaBI-EnSc4,10475
7
7
  nbdev/export.py,sha256=LEhn7UpfMSm9QKrC31q91Bsw-ZHd68DNv7MjhsNi15A,3275
8
8
  nbdev/extract_attachments.py,sha256=O4mS4EFIOXL_yQ3jmsnBStrWxGR_nPNvxLYXHtLeimw,2208
9
9
  nbdev/frontmatter.py,sha256=L9XbOPA99XuHSWU6eJfRIR4mBU4-NhDIQSP80EIk51g,2708
10
10
  nbdev/imports.py,sha256=f5Ynco14hsJyFCf43-uP_YARMhHADe6lM-20Mc_vXhw,95
11
- nbdev/maker.py,sha256=1hmOlElYhREqaJEc5jimiZ2Q5kkFUtQ9MNR05B-3L6c,9729
11
+ nbdev/maker.py,sha256=Q8K3lFMcLIxJ1OptGQcD6mjSSFz_UZwPKE6JIvKfnhQ,9767
12
12
  nbdev/merge.py,sha256=QrP8tdlPRfZZ-TH5dTRwj9jXr7jWEsrLwgcIVPSHJSs,4319
13
13
  nbdev/migrate.py,sha256=l2hO2Ymkjm1C3_JmFDsM-DN6bxgFeLjj-pBr1xNqunI,7317
14
14
  nbdev/process.py,sha256=7dl9U7JLL9wbJta-KKTTnkMktBVsK5s-y8OBxtfk68I,5863
15
15
  nbdev/processors.py,sha256=O5r2gXOCQlHI6aX0UFl_4PdaYV0fKPy6joYov_T7V88,11492
16
16
  nbdev/qmd.py,sha256=3Cskd8ynm25Hh7bo-_t0hxCMF6jqXxgq_VfkpLBKu_w,2958
17
- nbdev/quarto.py,sha256=uPburjx-OG9ruNTI08Ku_iOV5gerUUGNQUXDeOGmAco,12017
18
- nbdev/release.py,sha256=1rqBx77XPWSfb9JW8X7rTyaHz7wc4aRd3BHIkJafcKI,14229
17
+ nbdev/quarto.py,sha256=SYqJyElI6KMP4g16fZ87SmhK7NTYdnDIi1f1Y4GKO1I,12020
18
+ nbdev/release.py,sha256=6lwSBn9HkTNSl9jWIkYcKdBtWGo-LWl3YBjhQREuI2k,14167
19
19
  nbdev/serve.py,sha256=8q2qa82-osuIOpQamJ13Q_WEnnVZycxb8Vj467PGias,3020
20
20
  nbdev/serve_drv.py,sha256=IZ2acem_KKsXYYe0iUECiR_orkYLBkT1ZG_258ZS7SQ,657
21
- nbdev/showdoc.py,sha256=sWkpTLpWLUMQBsysHqyvS7czIVcmfkJ_pjSU3zcp-AI,9150
22
- nbdev/sync.py,sha256=ZKcWRJd49EaYJXeIB8hSa8oWHDrqRWoyRbGUGHDYxJg,2898
21
+ nbdev/showdoc.py,sha256=ZyT1HX9IXNl1hXRzzQ6XYu3NK6yLgPweatiItQbulbk,9151
22
+ nbdev/sync.py,sha256=BsdWf-1rw1WIPszL3Sw93U3Q5El2A-_9VnQz9_iP5Cw,3044
23
23
  nbdev/test.py,sha256=74db-sK_rnc69Q3beztibXDSZUeOk6M9nIiIORLHzlo,4397
24
- nbdev-2.3.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
- nbdev-2.3.23.dist-info/METADATA,sha256=WpH_OXekTry10XDDbLtfnv_HrMxysgOyG-DlOuHZGKM,10158
26
- nbdev-2.3.23.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
27
- nbdev-2.3.23.dist-info/entry_points.txt,sha256=lFZD1JQyZQI8x8PuaaSqbfnhInHhpm56nCR6n84nFKk,1272
28
- nbdev-2.3.23.dist-info/top_level.txt,sha256=3cWYLMuaXsZjz3TQRGEkWGs9Z8ieEDmYcq8TZS3y3vU,6
29
- nbdev-2.3.23.dist-info/RECORD,,
24
+ nbdev-2.3.26.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
25
+ nbdev-2.3.26.dist-info/METADATA,sha256=sNarWOTzuXPsKUBIiqKTordf8MS39d7qE5YpyjxbFxE,10339
26
+ nbdev-2.3.26.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
27
+ nbdev-2.3.26.dist-info/entry_points.txt,sha256=GMherdbuc27OmIuaaom4eNx5sTdCvAdNrZA6XLEZOA8,1326
28
+ nbdev-2.3.26.dist-info/top_level.txt,sha256=3cWYLMuaXsZjz3TQRGEkWGs9Z8ieEDmYcq8TZS3y3vU,6
29
+ nbdev-2.3.26.dist-info/RECORD,,
@@ -23,6 +23,7 @@ nbdev_readme = nbdev.quarto:nbdev_readme
23
23
  nbdev_release_both = nbdev.release:release_both
24
24
  nbdev_release_gh = nbdev.release:release_gh
25
25
  nbdev_release_git = nbdev.release:release_git
26
+ nbdev_requirements = nbdev.release:write_requirements
26
27
  nbdev_sidebar = nbdev.quarto:nbdev_sidebar
27
28
  nbdev_test = nbdev.test:nbdev_test
28
29
  nbdev_trust = nbdev.clean:nbdev_trust
File without changes