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
1010from 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
220221def 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
226244def 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
237255def _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+
239266def 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
252280def write_cells (cells , hdr , file , offset = 0 , cell_number = True , solo_nb = False ):
0 commit comments