diff --git a/nbdev/config.py b/nbdev/config.py index 30e4e2d30..ab0bfcfdc 100644 --- a/nbdev/config.py +++ b/nbdev/config.py @@ -316,20 +316,20 @@ def set_version(path, version): # %% ../nbs/api/01_config.ipynb #d00889e5 def bump_version(v, part=None, unbump=False): - "Bump `.postN` by default when present, otherwise a semver part counted from the right" + "Bump `.postN` by default when present, otherwise the part at 0-based index `part` of `v` (0=major, 1=minor, 2=patch), defaulting to the last part" v = v or '0.0.0' post = re.fullmatch(r'(.*)\.post(\d+)', v) if part is None and post: n = max(0, int(post[2]) + (-1 if unbump else 1)) return f'{post[1]}.post{n}' - if part is None: part = 2 parts = (post[1] if post else v).split('.') parts += ['0'] * (3 - len(parts)) - idx = len(parts) - 3 + part - parts[idx] = str(int(parts[idx]) + (-1 if unbump else 1)) - for i in range(idx+1, len(parts)): parts[i] = '0' + if part is None: part = len(parts) - 1 + parts[part] = str(int(parts[part]) + (-1 if unbump else 1)) + for i in range(part+1, len(parts)): parts[i] = '0' return '.'.join(parts) + # %% ../nbs/api/01_config.ipynb #e32583e6 def update_version(path=None): "Add __version__ to `path/__init__.py` if it doesn't exist" diff --git a/nbdev/release.py b/nbdev/release.py index 95c74b088..841447295 100644 --- a/nbdev/release.py +++ b/nbdev/release.py @@ -386,7 +386,7 @@ def release_both( # %% ../nbs/api/18_release.ipynb #c0f64b2c @call_parse def nbdev_bump_version( - part:int=None, # Release part to bump; defaults to post when present, otherwise patch + part:int=None, # 0-based version part to bump (0=major, 1=minor, 2=patch); defaults to post when present, otherwise the last part unbump:bool=False): # Reduce version instead of increasing it "Increment version in __init__.py by one" cfg = get_config() diff --git a/nbs/api/01_config.ipynb b/nbs/api/01_config.ipynb index 1ba47e186..0f5873cd2 100644 --- a/nbs/api/01_config.ipynb +++ b/nbs/api/01_config.ipynb @@ -808,19 +808,18 @@ "source": [ "#| export\n", "def bump_version(v, part=None, unbump=False):\n", - " \"Bump `.postN` by default when present, otherwise a semver part counted from the right\"\n", + " \"Bump `.postN` by default when present, otherwise the part at 0-based index `part` of `v` (0=major, 1=minor, 2=patch), defaulting to the last part\"\n", " v = v or '0.0.0'\n", " post = re.fullmatch(r'(.*)\\.post(\\d+)', v)\n", " if part is None and post:\n", " n = max(0, int(post[2]) + (-1 if unbump else 1))\n", " return f'{post[1]}.post{n}'\n", - " if part is None: part = 2\n", " parts = (post[1] if post else v).split('.')\n", " parts += ['0'] * (3 - len(parts))\n", - " idx = len(parts) - 3 + part\n", - " parts[idx] = str(int(parts[idx]) + (-1 if unbump else 1))\n", - " for i in range(idx+1, len(parts)): parts[i] = '0'\n", - " return '.'.join(parts)" + " if part is None: part = len(parts) - 1\n", + " parts[part] = str(int(parts[part]) + (-1 if unbump else 1))\n", + " for i in range(part+1, len(parts)): parts[i] = '0'\n", + " return '.'.join(parts)\n" ] }, { @@ -849,11 +848,14 @@ "test_eq(bump_version('1.2.3', part=0), '2.0.0')\n", "test_eq(bump_version('1.2.3', part=2, unbump=True), '1.2.2')\n", "test_eq(bump_version('2026.05.27.2'), '2026.05.27.3')\n", - "test_eq(bump_version('2026.05.27.2', part=1), '2026.05.28.0')\n", - "test_eq(bump_version('2026.05.27.2', part=0), '2026.6.0.0')\n", + "test_eq(bump_version('2026.05.27.2', part=3), '2026.05.27.3')\n", + "test_eq(bump_version('2026.05.27.2', part=2), '2026.05.28.0')\n", + "test_eq(bump_version('2026.05.27.2', part=1), '2026.6.0.0')\n", + "test_eq(bump_version('2026.05.27.2', part=0), '2027.0.0.0')\n", + "test_eq(bump_version('2026.01.28.0', part=3), '2026.01.28.1')\n", "test_eq(bump_version('0.0.2026082005.post1'), '0.0.2026082005.post2')\n", "test_eq(bump_version('0.0.2026082005.post2', unbump=True), '0.0.2026082005.post1')\n", - "test_eq(bump_version('0.0.2026082005.post1', part=2), '0.0.2026082006')" + "test_eq(bump_version('0.0.2026082005.post1', part=2), '0.0.2026082006')\n" ] }, { diff --git a/nbs/api/18_release.ipynb b/nbs/api/18_release.ipynb index a55212c76..1e9a9cc6f 100644 --- a/nbs/api/18_release.ipynb +++ b/nbs/api/18_release.ipynb @@ -1096,7 +1096,7 @@ "source": [ "## Bump Version\n", "\n", - "By default, a post-release version increments `.postN`; other versions increment their patch component. Passing `--part` explicitly selects a release component and removes the post suffix." + "By default, a post-release version increments `.postN`; other versions increment their last component. Passing `--part` explicitly selects a 0-based release component from the left (0=major, 1=minor, 2=patch for semver versions) and removes the post suffix." ] }, { @@ -1109,7 +1109,7 @@ "#| export\n", "@call_parse\n", "def nbdev_bump_version(\n", - " part:int=None, # Release part to bump; defaults to post when present, otherwise patch\n", + " part:int=None, # 0-based version part to bump (0=major, 1=minor, 2=patch); defaults to post when present, otherwise the last part\n", " unbump:bool=False): # Reduce version instead of increasing it\n", " \"Increment version in __init__.py by one\"\n", " cfg = get_config()\n", diff --git a/nbs/api/19_diff.ipynb b/nbs/api/19_diff.ipynb index b2e33e3ef..e1b9cbce9 100644 --- a/nbs/api/19_diff.ipynb +++ b/nbs/api/19_diff.ipynb @@ -618,9 +618,9 @@ "metadata": {}, "outputs": [], "source": [ - "assert all(len(l)<=121 for l in nb_diff(nb_path).splitlines())\n", + "assert all(len(l)<=MAXLEN+1 for l in nb_diff(nb_path).splitlines())\n", "assert any(l.endswith('…') for l in nb_diff(nb_path).splitlines())\n", - "assert all(len(l)>121 for l in nb_diff(nb_path, maxlen=0).splitlines() if l.startswith('+y'))" + "assert all(len(l)>MAXLEN for l in nb_diff(nb_path, maxlen=0).splitlines() if l.startswith('+y'))" ] }, {