Skip to content

Commit 849f50b

Browse files
author
Solveit
committed
fix regex matching project name
1 parent 8cd1b17 commit 849f50b

2 files changed

Lines changed: 36 additions & 29 deletions

File tree

nbdev/config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
267267
268268
[tool.uv]
269269
cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }]
270+
271+
[[tool.uv.index]]
272+
name = "pytorch-cpu"
273+
url = "https://download.pytorch.org/whl/cpu"
274+
explicit = true
270275
"""
271276

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

nbs/api/01_config.ipynb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -622,29 +622,7 @@
622622
"execution_count": null,
623623
"id": "6c2a835d",
624624
"metadata": {},
625-
"outputs": [
626-
{
627-
"data": {
628-
"text/markdown": [
629-
"<div class=\"prose\">\n",
630-
"\n",
631-
"```python\n",
632-
"print(create_output('text', 'text/plain'))\n",
633-
"```\n",
634-
"\n",
635-
"</div>"
636-
],
637-
"text/plain": [
638-
"Markdown(```python\n",
639-
"print(create_output('text', 'text/plain'))\n",
640-
"```)"
641-
]
642-
},
643-
"execution_count": 34,
644-
"metadata": {},
645-
"output_type": "execute_result"
646-
}
647-
],
625+
"outputs": [],
648626
"source": [
649627
"show_src(\"print(create_output('text', 'text/plain'))\")"
650628
]
@@ -677,6 +655,11 @@
677655
"\n",
678656
"[tool.uv]\n",
679657
"cache-keys = [{ file = \"pyproject.toml\" }, { file = \"setup.py\" }]\n",
658+
"\n",
659+
"[[tool.uv.index]]\n",
660+
"name = \"pytorch-cpu\"\n",
661+
"url = \"https://download.pytorch.org/whl/cpu\"\n",
662+
"explicit = true\n",
680663
"\"\"\""
681664
]
682665
},
@@ -833,6 +816,28 @@
833816
" if get_config().get('update_pyproject', True): update_proj(path.parent)"
834817
]
835818
},
819+
{
820+
"cell_type": "code",
821+
"execution_count": null,
822+
"id": "066be7c6",
823+
"metadata": {},
824+
"outputs": [],
825+
"source": [
826+
"with tempfile.TemporaryDirectory() as d:\n",
827+
" d = Path(d)\n",
828+
" cfg_text = (pyproj_tmpl.replace('name = \"FILL_IN\"', 'name = \"testpkg\"').replace('requires-python=\"FILL_IN\"', 'requires-python=\">=3.10\"'))\n",
829+
" cfg_text += '\\n[tool.nbdev]\\n'\n",
830+
" (d/_pyproj).write_text(cfg_text)\n",
831+
" (d/'testpkg').mkdir()\n",
832+
"\n",
833+
" with working_directory(d):\n",
834+
" update_proj(d)\n",
835+
"\n",
836+
" result = (d/_pyproj).read_text()\n",
837+
" assert 'name = \"testpkg\"' in result\n",
838+
" assert 'name = \"pytorch-cpu\"' in result, \"update_proj incorrectly modified the uv index name!\""
839+
]
840+
},
836841
{
837842
"cell_type": "markdown",
838843
"id": "63b789b2",
@@ -947,10 +952,7 @@
947952
]
948953
}
949954
],
950-
"metadata": {
951-
"solveit_dialog_mode": "learning",
952-
"solveit_ver": 2
953-
},
955+
"metadata": {},
954956
"nbformat": 4,
955957
"nbformat_minor": 5
956958
}

0 commit comments

Comments
 (0)