Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,16 @@ def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')

[tool.uv]
cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }]

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
"""

# %% ../nbs/api/01_config.ipynb #f1c85f45
_re_version = re.compile(r'^__version__\s*=\s*[\'"]([^\'"]+)[\'"]', re.MULTILINE)
_re_proj = re.compile(r'^name\s*=\s*".*$', re.MULTILINE)
_re_proj = re.compile(r'(\[project\](?:\n(?!\[).*)*?\n)name\s*=\s*"[^"]*"')
_re_reqpy = re.compile(r'^requires-python\s*=\s*".*$', re.MULTILINE)
_init = '__init__.py'
_pyproj = 'pyproject.toml'
Expand Down Expand Up @@ -320,7 +325,7 @@ def update_proj(path):
fname = path/_pyproj
if not fname.exists(): fname.write_text(pyproj_tmpl)
txt = fname.read_text()
txt = _re_proj.sub(f'name = "{get_config().lib_name}"', txt)
txt = _re_proj.sub(rf'\1name = "{get_config().lib_name}"', txt)
txt = _re_reqpy.sub(f'requires-python = ">={get_config().min_python}"', txt)
fname.write_text(txt)

Expand Down
49 changes: 30 additions & 19 deletions nbs/api/01_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -622,23 +622,7 @@
"execution_count": null,
"id": "6c2a835d",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"```python\n",
"print(create_output('text', 'text/plain'))\n",
"```"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"show_src(\"print(create_output('text', 'text/plain'))\")"
]
Expand Down Expand Up @@ -671,6 +655,11 @@
"\n",
"[tool.uv]\n",
"cache-keys = [{ file = \"pyproject.toml\" }, { file = \"setup.py\" }]\n",
"\n",
"[[tool.uv.index]]\n",
"name = \"pytorch-cpu\"\n",
"url = \"https://download.pytorch.org/whl/cpu\"\n",
"explicit = true\n",
"\"\"\""
]
},
Expand All @@ -683,7 +672,7 @@
"source": [
"#| export\n",
"_re_version = re.compile(r'^__version__\\s*=\\s*[\\'\"]([^\\'\"]+)[\\'\"]', re.MULTILINE)\n",
"_re_proj = re.compile(r'^name\\s*=\\s*\".*$', re.MULTILINE)\n",
"_re_proj = re.compile(r'(\\[project\\](?:\\n(?!\\[).*)*?\\n)name\\s*=\\s*\"[^\"]*\"')\n",
"_re_reqpy = re.compile(r'^requires-python\\s*=\\s*\".*$', re.MULTILINE)\n",
"_init = '__init__.py'\n",
"_pyproj = 'pyproject.toml'"
Expand Down Expand Up @@ -800,7 +789,7 @@
" fname = path/_pyproj\n",
" if not fname.exists(): fname.write_text(pyproj_tmpl)\n",
" txt = fname.read_text()\n",
" txt = _re_proj.sub(f'name = \"{get_config().lib_name}\"', txt)\n",
" txt = _re_proj.sub(rf'\\1name = \"{get_config().lib_name}\"', txt)\n",
" txt = _re_reqpy.sub(f'requires-python = \">={get_config().min_python}\"', txt)\n",
" fname.write_text(txt)"
]
Expand All @@ -827,6 +816,28 @@
" if get_config().get('update_pyproject', True): update_proj(path.parent)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "066be7c6",
"metadata": {},
"outputs": [],
"source": [
"with tempfile.TemporaryDirectory() as d:\n",
" d = Path(d)\n",
" cfg_text = (pyproj_tmpl.replace('name = \"FILL_IN\"', 'name = \"testpkg\"').replace('requires-python=\"FILL_IN\"', 'requires-python=\">=3.10\"'))\n",
" cfg_text += '\\n[tool.nbdev]\\n'\n",
" (d/_pyproj).write_text(cfg_text)\n",
" (d/'testpkg').mkdir()\n",
"\n",
" with working_directory(d):\n",
" update_proj(d)\n",
"\n",
" result = (d/_pyproj).read_text()\n",
" assert 'name = \"testpkg\"' in result\n",
" assert 'name = \"pytorch-cpu\"' in result, \"update_proj incorrectly modified the uv index name!\""
]
},
{
"cell_type": "markdown",
"id": "63b789b2",
Expand Down