Skip to content

Commit e3c3bec

Browse files
committed
fixes #1515
1 parent 743ca6b commit e3c3bec

File tree

6 files changed

+82
-10
lines changed

6 files changed

+82
-10
lines changed

nbdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.3.38"
1+
__version__ = "2.4.0"
22

33
from .doclinks import nbdev_export
44
from .showdoc import show_doc

nbdev/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'nbdev.config.is_nbdev': ('api/config.html#is_nbdev', 'nbdev/config.py'),
4747
'nbdev.config.nbdev_create_config': ('api/config.html#nbdev_create_config', 'nbdev/config.py'),
4848
'nbdev.config.show_src': ('api/config.html#show_src', 'nbdev/config.py'),
49+
'nbdev.config.update_proj': ('api/config.html#update_proj', 'nbdev/config.py'),
4950
'nbdev.config.update_version': ('api/config.html#update_version', 'nbdev/config.py'),
5051
'nbdev.config.write_cells': ('api/config.html#write_cells', 'nbdev/config.py')},
5152
'nbdev.doclinks': { 'nbdev.doclinks.NbdevLookup': ('api/doclinks.html#nbdevlookup', 'nbdev/doclinks.py'),

nbdev/config.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
44

55
# %% auto 0
6-
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'is_nbdev', 'create_output', 'show_src', 'update_version',
7-
'add_init', 'write_cells']
6+
__all__ = ['pyproj_tmpl', 'nbdev_create_config', 'get_config', 'config_key', 'is_nbdev', 'create_output', 'show_src',
7+
'update_version', 'update_proj', 'add_init', 'write_cells']
88

99
# %% ../nbs/api/01_config.ipynb
1010
from datetime import datetime
@@ -49,7 +49,7 @@ def _apply_defaults(
4949
license='apache2', # License for the package
5050
copyright:str=None, # Copyright for the package, defaults to '`current_year` onwards, `author`'
5151
status='3', # Development status PyPI classifier
52-
min_python='3.7', # Minimum Python version PyPI classifier
52+
min_python='3.9', # Minimum Python version PyPI classifier
5353
audience='Developers', # Intended audience PyPI classifier
5454
language='English', # Language PyPI classifier
5555
recursive:bool_arg=True, # Include subfolders in notebook globs?
@@ -63,6 +63,7 @@ def _apply_defaults(
6363
clear_all:bool_arg=False, # Remove all cell metadata and cell outputs?
6464
cell_number:bool_arg=True, # Add cell number to the exported file
6565
put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export
66+
update_pyproject:bool_arg=True, # Create/update pyproject.toml with correct project name
6667
skip_procs:str='', # A comma-separated list of processors that you want to skip
6768
):
6869
"Apply default settings where missing in `cfg`."
@@ -142,7 +143,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
142143
143144
'''
144145
_nbdev_cfg_sections = {'Python library': 'repo lib_name version min_python license black_formatting',
145-
'nbdev': 'doc_path lib_path nbs_path recursive tst_flags put_version_in_init',
146+
'nbdev': 'doc_path lib_path nbs_path recursive tst_flags put_version_in_init update_pyproject',
146147
'Docs': 'branch custom_sidebar doc_host doc_baseurl git_url title',
147148
'PyPI': 'audience author author_email copyright description keywords language status user'}
148149
_nbdev_cfg_tail = '''### Optional ###
@@ -219,9 +220,26 @@ def create_output(txt, mime):
219220
# %% ../nbs/api/01_config.ipynb
220221
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
221222

223+
# %% ../nbs/api/01_config.ipynb
224+
pyproj_tmpl = """[build-system]
225+
requires = ["setuptools>=64.0"]
226+
build-backend = "setuptools.build_meta"
227+
228+
[project]
229+
name = "FILL_IN"
230+
requires-python="FILL_IN"
231+
dynamic = ["description", "version","dependencies", "optional-dependencies", "readme", "requires-python", "license", "authors", "keywords", "classifiers", "entry-points", "urls"]
232+
233+
[tool.uv]
234+
cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
235+
"""
236+
222237
# %% ../nbs/api/01_config.ipynb
223238
_re_version = re.compile(r'^__version__\s*=.*$', re.MULTILINE)
239+
_re_proj = re.compile(r'^name\s*=\s*".*$', re.MULTILINE)
240+
_re_reqpy = re.compile(r'^requires-python\s*=\s*".*$', re.MULTILINE)
224241
_init = '__init__.py'
242+
_pyproj = 'pyproject.toml'
225243

226244
def update_version(path=None):
227245
"Add or update `__version__` in the main `__init__.py` of the library."
@@ -236,6 +254,15 @@ def update_version(path=None):
236254

237255
def _has_py(fs): return any(1 for f in fs if f.endswith('.py'))
238256

257+
def update_proj(path):
258+
"Create or update `pyproject.toml` in the project root."
259+
fname = path/_pyproj
260+
if not fname.exists(): fname.write_text(pyproj_tmpl)
261+
txt = fname.read_text()
262+
txt = _re_proj.sub(f'name="{get_config().lib_name}"', txt)
263+
txt = _re_reqpy.sub(f'requires-python=">={get_config().min_python}"', txt)
264+
fname.write_text(txt)
265+
239266
def add_init(path=None):
240267
"Add `__init__.py` in all subdirs of `path` containing python files if it's not there already."
241268
# we add the lowest-level `__init__.py` files first, which ensures _has_py succeeds for parent modules
@@ -247,6 +274,7 @@ def add_init(path=None):
247274
subds = (os.listdir(r/d) for d in ds)
248275
if _has_py(fs) or any(filter(_has_py, subds)) and not (r/_init).exists(): (r/_init).touch()
249276
if get_config().get('put_version_in_init', True): update_version(path)
277+
if get_config().get('update_pyproject', True): update_proj(path.parent)
250278

251279
# %% ../nbs/api/01_config.ipynb
252280
def write_cells(cells, hdr, file, offset=0, cell_number=True, solo_nb=False):

nbs/api/01_config.ipynb

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
" license='apache2', # License for the package\n",
140140
" copyright:str=None, # Copyright for the package, defaults to '`current_year` onwards, `author`'\n",
141141
" status='3', # Development status PyPI classifier\n",
142-
" min_python='3.7', # Minimum Python version PyPI classifier\n",
142+
" min_python='3.9', # Minimum Python version PyPI classifier\n",
143143
" audience='Developers', # Intended audience PyPI classifier\n",
144144
" language='English', # Language PyPI classifier\n",
145145
" recursive:bool_arg=True, # Include subfolders in notebook globs?\n",
@@ -153,6 +153,7 @@
153153
" clear_all:bool_arg=False, # Remove all cell metadata and cell outputs?\n",
154154
" cell_number:bool_arg=True, # Add cell number to the exported file\n",
155155
" put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export\n",
156+
" update_pyproject:bool_arg=True, # Create/update pyproject.toml with correct project name\n",
156157
" skip_procs:str='', # A comma-separated list of processors that you want to skip\n",
157158
"):\n",
158159
" \"Apply default settings where missing in `cfg`.\"\n",
@@ -326,7 +327,7 @@
326327
"\n",
327328
"'''\n",
328329
"_nbdev_cfg_sections = {'Python library': 'repo lib_name version min_python license black_formatting',\n",
329-
" 'nbdev': 'doc_path lib_path nbs_path recursive tst_flags put_version_in_init',\n",
330+
" 'nbdev': 'doc_path lib_path nbs_path recursive tst_flags put_version_in_init update_pyproject',\n",
330331
" 'Docs': 'branch custom_sidebar doc_host doc_baseurl git_url title',\n",
331332
" 'PyPI': 'audience author author_email copyright description keywords language status user'}\n",
332333
"_nbdev_cfg_tail = '''### Optional ###\n",
@@ -669,6 +670,27 @@
669670
"## Exporting a basic module"
670671
]
671672
},
673+
{
674+
"cell_type": "code",
675+
"execution_count": null,
676+
"metadata": {},
677+
"outputs": [],
678+
"source": [
679+
"#| export\n",
680+
"pyproj_tmpl = \"\"\"[build-system]\n",
681+
"requires = [\"setuptools>=64.0\"]\n",
682+
"build-backend = \"setuptools.build_meta\"\n",
683+
"\n",
684+
"[project]\n",
685+
"name = \"FILL_IN\"\n",
686+
"requires-python=\"FILL_IN\"\n",
687+
"dynamic = [\"description\", \"version\",\"dependencies\", \"optional-dependencies\", \"readme\", \"requires-python\", \"license\", \"authors\", \"keywords\", \"classifiers\", \"entry-points\", \"urls\"]\n",
688+
"\n",
689+
"[tool.uv]\n",
690+
"cache-keys = [{ file = \"pyproject.toml\" }, { file = \"settings.ini\" }, { file = \"setup.py\" }]\n",
691+
"\"\"\""
692+
]
693+
},
672694
{
673695
"cell_type": "code",
674696
"execution_count": null,
@@ -677,7 +699,10 @@
677699
"source": [
678700
"#|export\n",
679701
"_re_version = re.compile(r'^__version__\\s*=.*$', re.MULTILINE)\n",
702+
"_re_proj = re.compile(r'^name\\s*=\\s*\".*$', re.MULTILINE)\n",
703+
"_re_reqpy = re.compile(r'^requires-python\\s*=\\s*\".*$', re.MULTILINE)\n",
680704
"_init = '__init__.py'\n",
705+
"_pyproj = 'pyproject.toml'\n",
681706
"\n",
682707
"def update_version(path=None):\n",
683708
" \"Add or update `__version__` in the main `__init__.py` of the library.\"\n",
@@ -692,6 +717,15 @@
692717
"\n",
693718
"def _has_py(fs): return any(1 for f in fs if f.endswith('.py'))\n",
694719
"\n",
720+
"def update_proj(path):\n",
721+
" \"Create or update `pyproject.toml` in the project root.\"\n",
722+
" fname = path/_pyproj\n",
723+
" if not fname.exists(): fname.write_text(pyproj_tmpl)\n",
724+
" txt = fname.read_text()\n",
725+
" txt = _re_proj.sub(f'name=\"{get_config().lib_name}\"', txt)\n",
726+
" txt = _re_reqpy.sub(f'requires-python=\">={get_config().min_python}\"', txt)\n",
727+
" fname.write_text(txt)\n",
728+
"\n",
695729
"def add_init(path=None):\n",
696730
" \"Add `__init__.py` in all subdirs of `path` containing python files if it's not there already.\"\n",
697731
" # we add the lowest-level `__init__.py` files first, which ensures _has_py succeeds for parent modules\n",
@@ -702,7 +736,8 @@
702736
" r = Path(r)\n",
703737
" subds = (os.listdir(r/d) for d in ds)\n",
704738
" if _has_py(fs) or any(filter(_has_py, subds)) and not (r/_init).exists(): (r/_init).touch()\n",
705-
" if get_config().get('put_version_in_init', True): update_version(path)"
739+
" if get_config().get('put_version_in_init', True): update_version(path)\n",
740+
" if get_config().get('update_pyproject', True): update_proj(path.parent)"
706741
]
707742
},
708743
{

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
[build-system]
22
requires = ["setuptools>=64.0"]
33
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name="nbdev"
7+
requires-python=">=3.9"
8+
dynamic = ["description", "version","dependencies", "optional-dependencies", "readme", "license", "authors", "keywords", "classifiers", "entry-points", "urls"]
9+
10+
[tool.uv]
11+
cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]

settings.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ user = AnswerDotAI
88
author = Jeremy Howard and Hamel Husain
99
author_email = [email protected]
1010
branch = main
11-
min_python = 3.7
12-
version = 2.3.38
11+
min_python = 3.9
12+
version = 2.4.0
1313
audience = Developers
1414
language = English
1515
custom_sidebar = True

0 commit comments

Comments
 (0)