3
3
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
4
4
5
5
# %% 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' ]
8
8
9
9
# %% ../nbs/api/01_config.ipynb
10
10
from datetime import datetime
@@ -49,7 +49,7 @@ def _apply_defaults(
49
49
license = 'apache2' , # License for the package
50
50
copyright :str = None , # Copyright for the package, defaults to '`current_year` onwards, `author`'
51
51
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
53
53
audience = 'Developers' , # Intended audience PyPI classifier
54
54
language = 'English' , # Language PyPI classifier
55
55
recursive :bool_arg = True , # Include subfolders in notebook globs?
@@ -63,6 +63,7 @@ def _apply_defaults(
63
63
clear_all :bool_arg = False , # Remove all cell metadata and cell outputs?
64
64
cell_number :bool_arg = True , # Add cell number to the exported file
65
65
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
66
67
skip_procs :str = '' , # A comma-separated list of processors that you want to skip
67
68
):
68
69
"Apply default settings where missing in `cfg`."
@@ -142,7 +143,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
142
143
143
144
'''
144
145
_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 ' ,
146
147
'Docs' : 'branch custom_sidebar doc_host doc_baseurl git_url title' ,
147
148
'PyPI' : 'audience author author_email copyright description keywords language status user' }
148
149
_nbdev_cfg_tail = '''### Optional ###
@@ -219,9 +220,26 @@ def create_output(txt, mime):
219
220
# %% ../nbs/api/01_config.ipynb
220
221
def show_src (src , lang = 'python' ): return Markdown (f'```{ lang } \n { src } \n ```' )
221
222
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
+
222
237
# %% ../nbs/api/01_config.ipynb
223
238
_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 )
224
241
_init = '__init__.py'
242
+ _pyproj = 'pyproject.toml'
225
243
226
244
def update_version (path = None ):
227
245
"Add or update `__version__` in the main `__init__.py` of the library."
@@ -236,6 +254,15 @@ def update_version(path=None):
236
254
237
255
def _has_py (fs ): return any (1 for f in fs if f .endswith ('.py' ))
238
256
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
+
239
266
def add_init (path = None ):
240
267
"Add `__init__.py` in all subdirs of `path` containing python files if it's not there already."
241
268
# 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):
247
274
subds = (os .listdir (r / d ) for d in ds )
248
275
if _has_py (fs ) or any (filter (_has_py , subds )) and not (r / _init ).exists (): (r / _init ).touch ()
249
276
if get_config ().get ('put_version_in_init' , True ): update_version (path )
277
+ if get_config ().get ('update_pyproject' , True ): update_proj (path .parent )
250
278
251
279
# %% ../nbs/api/01_config.ipynb
252
280
def write_cells (cells , hdr , file , offset = 0 , cell_number = True , solo_nb = False ):
0 commit comments