diff --git a/nbdev/config.py b/nbdev/config.py index f5189d5c0..4dbbc303b 100644 --- a/nbdev/config.py +++ b/nbdev/config.py @@ -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' @@ -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) diff --git a/nbs/api/01_config.ipynb b/nbs/api/01_config.ipynb index 5452731fa..027462344 100644 --- a/nbs/api/01_config.ipynb +++ b/nbs/api/01_config.ipynb @@ -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": [ - "" - ] - }, - "execution_count": null, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "show_src(\"print(create_output('text', 'text/plain'))\")" ] @@ -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", "\"\"\"" ] }, @@ -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'" @@ -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)" ] @@ -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",