|
30 | 30 | "outputs": [], |
31 | 31 | "source": [ |
32 | 32 | "#| export\n", |
33 | | - "from datetime import datetime\n", |
34 | 33 | "from fastcore.docments import *\n", |
35 | 34 | "from fastcore.utils import *\n", |
36 | 35 | "from fastcore.meta import *\n", |
37 | 36 | "from fastcore.script import *\n", |
38 | 37 | "from fastcore.style import *\n", |
39 | 38 | "from fastcore.xdg import *\n", |
40 | 39 | "\n", |
41 | | - "import ast,importlib,re,warnings\n", |
| 40 | + "import ast,importlib,re\n", |
42 | 41 | "from IPython.display import Markdown\n", |
43 | 42 | "from fastcore.nbio import read_nb,NbCell\n", |
44 | | - "from urllib.error import HTTPError\n", |
45 | 43 | "\n", |
46 | 44 | "try: import tomllib\n", |
47 | 45 | "except ImportError: import tomli as tomllib" |
|
138 | 136 | " from ghapi.all import call_gh, APIError\n", |
139 | 137 | " try: r = call_gh('repos.get', owner=owner, repo=repo)\n", |
140 | 138 | " except APIError:\n", |
| 139 | + " # chkstyle: ignore-node\n", |
141 | 140 | " msg= [f\"\"\"Could not access repo: {owner}/{repo} to find your default branch - `{default_branch}` assumed.\n", |
142 | 141 | "Edit `pyproject.toml` if this is incorrect.\n", |
143 | 142 | "In the future, you can allow nbdev to see private repos by setting the environment variable GITHUB_TOKEN as described here:\n", |
|
398 | 397 | " if 'lib_path' not in self: self['lib_path'] = self.lib_name.replace('-', '_')\n", |
399 | 398 | "\n", |
400 | 399 | " @property\n", |
401 | | - " def version(self):\n", |
402 | | - " return read_version(self.config_path / self['lib_path']) or '0.0.1'\n", |
| 400 | + " def version(self): return read_version(self.config_path / self['lib_path']) or '0.0.1'\n", |
403 | 401 | "\n", |
404 | 402 | " @property\n", |
405 | 403 | " def d(self): return {k:v for k,v in super().items()}\n", |
|
604 | 602 | "def create_output(txt, mime):\n", |
605 | 603 | " \"Add a cell output containing `txt` of the `mime` text MIME sub-type\"\n", |
606 | 604 | " return [dict(data={f\"text/{mime}\": str(txt).splitlines(True)},\n", |
607 | | - " execution_count=1, metadata={}, output_type=\"execute_result\")]" |
| 605 | + " execution_count=1, metadata={}, output_type=\"execute_result\")]" |
608 | 606 | ] |
609 | 607 | }, |
610 | 608 | { |
|
810 | 808 | "source": [ |
811 | 809 | "#| export\n", |
812 | 810 | "def bump_version(v, part=2, unbump=False):\n", |
813 | | - " \"Bump semver string `v` at index `part` (0=major, 1=minor, 2=patch)\"\n", |
| 811 | + " \"Bump semver part `part` (0=major, 1=minor, 2=patch), counted from the right\"\n", |
814 | 812 | " parts = (v or '0.0.0').split('.')\n", |
815 | 813 | " parts += ['0'] * (3 - len(parts))\n", |
816 | | - " parts[part] = str(int(parts[part]) + (-1 if unbump else 1))\n", |
817 | | - " for i in range(part+1, 3): parts[i] = '0'\n", |
818 | | - " return '.'.join(parts[:3])" |
| 814 | + " idx = len(parts) - 3 + part\n", |
| 815 | + " parts[idx] = str(int(parts[idx]) + (-1 if unbump else 1))\n", |
| 816 | + " for i in range(idx+1, len(parts)): parts[i] = '0'\n", |
| 817 | + " return '.'.join(parts)" |
819 | 818 | ] |
820 | 819 | }, |
821 | 820 | { |
|
842 | 841 | "test_eq(bump_version('1.2.3'), '1.2.4')\n", |
843 | 842 | "test_eq(bump_version('1.2.3', part=1), '1.3.0')\n", |
844 | 843 | "test_eq(bump_version('1.2.3', part=0), '2.0.0')\n", |
845 | | - "test_eq(bump_version('1.2.3', part=2, unbump=True), '1.2.2')" |
| 844 | + "test_eq(bump_version('1.2.3', part=2, unbump=True), '1.2.2')\n", |
| 845 | + "test_eq(bump_version('2026.05.27.2'), '2026.05.27.3')\n", |
| 846 | + "test_eq(bump_version('2026.05.27.2', part=1), '2026.05.28.0')\n", |
| 847 | + "test_eq(bump_version('2026.05.27.2', part=0), '2026.6.0.0')" |
846 | 848 | ] |
847 | 849 | }, |
848 | 850 | { |
|
1038 | 1040 | "from fastcore.nbio import new_nb, mk_cell, write_nb\n", |
1039 | 1041 | "with tempfile.TemporaryDirectory() as d:\n", |
1040 | 1042 | " d = Path(d)\n", |
1041 | | - " p = d/'pkg'; p.mkdir()\n", |
| 1043 | + " p = d/'pkg'\n", |
| 1044 | + " p.mkdir()\n", |
1042 | 1045 | " (p/'a.py').write_text('\"\"\"A module\\nspanning lines\\n\\nMore about a.\\n\\nDocs: http://x\"\"\"\\n')\n", |
1043 | 1046 | " (p/'b.py').write_text('\"\"\"B summary\\n\\nDocs: http://y\"\"\"\\n')\n", |
1044 | 1047 | " (p/'_c.py').write_text('\"\"\"Private\\n\\nwith\\nmany\\nlines\"\"\"\\n')\n", |
|
1054 | 1057 | " update_init_mdoc(p, desc='Test pkg')\n", |
1055 | 1058 | " assert '- `pkg.b`: B summary' in (p/'__init__.py').read_text()\n", |
1056 | 1059 | " idx = new_nb([mk_cell('# Pkg\\n> tagline', 'markdown'), mk_cell('#| export\\nIntro para.', 'markdown'),\n", |
1057 | | - " mk_cell('#| exportd\\nprint(1)'), mk_cell('Untagged prose.', 'markdown')])\n", |
| 1060 | + " mk_cell('#| exportd\\nprint(1)'), mk_cell('Untagged prose.', 'markdown')])\n", |
1058 | 1061 | " write_nb(idx, d/'index.ipynb')\n", |
1059 | 1062 | " m = pkg_mdoc(p, desc='Test pkg', index_nb=d/'index.ipynb')\n", |
1060 | 1063 | " assert m.startswith('Test pkg\\n\\nIntro para.\\n\\n```python\\nprint(1)\\n```\\n\\nModules:\\n\\n- `pkg.a`')\n", |
1061 | 1064 | " assert 'Untagged' not in m and 'tagline' not in m\n", |
1062 | | - " q = d/'empty_pkg'; q.mkdir()\n", |
| 1065 | + " q = d/'empty_pkg'\n", |
| 1066 | + " q.mkdir()\n", |
1063 | 1067 | " test_eq(pkg_mdoc(q, desc='D', index_nb=d/'index.ipynb'),\n", |
1064 | | - " 'D\\n\\nIntro para.\\n\\n```python\\nprint(1)\\n```') # intro alone still makes a docstring" |
| 1068 | + " 'D\\n\\nIntro para.\\n\\n```python\\nprint(1)\\n```') # intro alone still makes a docstring" |
1065 | 1069 | ] |
1066 | 1070 | }, |
1067 | 1071 | { |
|
1074 | 1078 | "#| hide\n", |
1075 | 1079 | "with tempfile.TemporaryDirectory() as d:\n", |
1076 | 1080 | " d = Path(d)\n", |
1077 | | - " p = d/'pkg'; p.mkdir()\n", |
| 1081 | + " p = d/'pkg'\n", |
| 1082 | + " p.mkdir()\n", |
1078 | 1083 | " (p/'a.py').write_text('\"\"\"A module\\n\\nMore about a.\\n\\nDocs: http://x/a.html.md\"\"\"\\n')\n", |
1079 | 1084 | " (p/'b.py').write_text('\"\"\"B, no url\\n\\nSubstantive tho.\\n\\nno docs line\"\"\"\\n')\n", |
1080 | 1085 | " (p/'d.py').write_text('\"\"\"D two urls\\n\\nBody.\\n\\nDocs: http://x/1.md and http://x/2.md\"\"\"\\n')\n", |
1081 | 1086 | " idx = new_nb([mk_cell('# Pkg\\n> tagline', 'markdown'), mk_cell('#| export\\nIntro para.', 'markdown')])\n", |
1082 | 1087 | " write_nb(idx, d/'index.ipynb')\n", |
1083 | 1088 | " s = pkg_llms(p, desc='Test pkg', index_nb=d/'index.ipynb')\n", |
| 1089 | + " # chkstyle: ignore-node\n", |
1084 | 1090 | " test_eq(s, '''# pkg\n", |
1085 | 1091 | "\n", |
1086 | 1092 | "> Test pkg\n", |
|
1120 | 1126 | " (d/_pyproj).write_text(cfg_text)\n", |
1121 | 1127 | " (d/'testpkg').mkdir()\n", |
1122 | 1128 | "\n", |
1123 | | - " with working_directory(d):\n", |
1124 | | - " update_proj(d)\n", |
| 1129 | + " with working_directory(d): update_proj(d)\n", |
1125 | 1130 | "\n", |
1126 | 1131 | " result = (d/_pyproj).read_text()\n", |
1127 | 1132 | " assert 'name = \"testpkg\"' in result" |
|
0 commit comments