|
622 | 622 | "execution_count": null, |
623 | 623 | "id": "6c2a835d", |
624 | 624 | "metadata": {}, |
625 | | - "outputs": [ |
626 | | - { |
627 | | - "data": { |
628 | | - "text/markdown": [ |
629 | | - "```python\n", |
630 | | - "print(create_output('text', 'text/plain'))\n", |
631 | | - "```" |
632 | | - ], |
633 | | - "text/plain": [ |
634 | | - "<IPython.core.display.Markdown object>" |
635 | | - ] |
636 | | - }, |
637 | | - "execution_count": null, |
638 | | - "metadata": {}, |
639 | | - "output_type": "execute_result" |
640 | | - } |
641 | | - ], |
| 625 | + "outputs": [], |
642 | 626 | "source": [ |
643 | 627 | "show_src(\"print(create_output('text', 'text/plain'))\")" |
644 | 628 | ] |
|
671 | 655 | "\n", |
672 | 656 | "[tool.uv]\n", |
673 | 657 | "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", |
674 | 663 | "\"\"\"" |
675 | 664 | ] |
676 | 665 | }, |
|
683 | 672 | "source": [ |
684 | 673 | "#| export\n", |
685 | 674 | "_re_version = re.compile(r'^__version__\\s*=\\s*[\\'\"]([^\\'\"]+)[\\'\"]', re.MULTILINE)\n", |
686 | | - "_re_proj = re.compile(r'^name\\s*=\\s*\".*$', re.MULTILINE)\n", |
| 675 | + "_re_proj = re.compile(r'(\\[project\\](?:\\n(?!\\[).*)*?\\n)name\\s*=\\s*\"[^\"]*\"')\n", |
687 | 676 | "_re_reqpy = re.compile(r'^requires-python\\s*=\\s*\".*$', re.MULTILINE)\n", |
688 | 677 | "_init = '__init__.py'\n", |
689 | 678 | "_pyproj = 'pyproject.toml'" |
|
800 | 789 | " fname = path/_pyproj\n", |
801 | 790 | " if not fname.exists(): fname.write_text(pyproj_tmpl)\n", |
802 | 791 | " txt = fname.read_text()\n", |
803 | | - " txt = _re_proj.sub(f'name = \"{get_config().lib_name}\"', txt)\n", |
| 792 | + " txt = _re_proj.sub(rf'\\1name = \"{get_config().lib_name}\"', txt)\n", |
804 | 793 | " txt = _re_reqpy.sub(f'requires-python = \">={get_config().min_python}\"', txt)\n", |
805 | 794 | " fname.write_text(txt)" |
806 | 795 | ] |
|
827 | 816 | " if get_config().get('update_pyproject', True): update_proj(path.parent)" |
828 | 817 | ] |
829 | 818 | }, |
| 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 | + }, |
830 | 841 | { |
831 | 842 | "cell_type": "markdown", |
832 | 843 | "id": "63b789b2", |
|
0 commit comments