Skip to content

Commit 8bd59d4

Browse files
authored
Support post-release version bumps
1 parent 69de559 commit 8bd59d4

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

nbdev/config.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,15 @@ def set_version(path, version):
315315
fname.write_text(code)
316316

317317
# %% ../nbs/api/01_config.ipynb #d00889e5
318-
def bump_version(v, part=2, unbump=False):
319-
"Bump semver part `part` (0=major, 1=minor, 2=patch), counted from the right"
320-
parts = (v or '0.0.0').split('.')
318+
def bump_version(v, part=None, unbump=False):
319+
"Bump `.postN` by default when present, otherwise a semver part counted from the right"
320+
v = v or '0.0.0'
321+
post = re.fullmatch(r'(.*)\.post(\d+)', v)
322+
if part is None and post:
323+
n = max(0, int(post[2]) + (-1 if unbump else 1))
324+
return f'{post[1]}.post{n}'
325+
if part is None: part = 2
326+
parts = (post[1] if post else v).split('.')
321327
parts += ['0'] * (3 - len(parts))
322328
idx = len(parts) - 3 + part
323329
parts[idx] = str(int(parts[idx]) + (-1 if unbump else 1))

nbdev/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def release_both(
386386
# %% ../nbs/api/18_release.ipynb #c0f64b2c
387387
@call_parse
388388
def nbdev_bump_version(
389-
part:int=2, # Part of version to bump
389+
part:int=None, # Release part to bump; defaults to post when present, otherwise patch
390390
unbump:bool=False): # Reduce version instead of increasing it
391391
"Increment version in __init__.py by one"
392392
cfg = get_config()

nbs/api/01_config.ipynb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,15 @@
807807
"outputs": [],
808808
"source": [
809809
"#| export\n",
810-
"def bump_version(v, part=2, unbump=False):\n",
811-
" \"Bump semver part `part` (0=major, 1=minor, 2=patch), counted from the right\"\n",
812-
" parts = (v or '0.0.0').split('.')\n",
810+
"def bump_version(v, part=None, unbump=False):\n",
811+
" \"Bump `.postN` by default when present, otherwise a semver part counted from the right\"\n",
812+
" v = v or '0.0.0'\n",
813+
" post = re.fullmatch(r'(.*)\\.post(\\d+)', v)\n",
814+
" if part is None and post:\n",
815+
" n = max(0, int(post[2]) + (-1 if unbump else 1))\n",
816+
" return f'{post[1]}.post{n}'\n",
817+
" if part is None: part = 2\n",
818+
" parts = (post[1] if post else v).split('.')\n",
813819
" parts += ['0'] * (3 - len(parts))\n",
814820
" idx = len(parts) - 3 + part\n",
815821
" parts[idx] = str(int(parts[idx]) + (-1 if unbump else 1))\n",
@@ -844,7 +850,10 @@
844850
"test_eq(bump_version('1.2.3', part=2, unbump=True), '1.2.2')\n",
845851
"test_eq(bump_version('2026.05.27.2'), '2026.05.27.3')\n",
846852
"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')"
853+
"test_eq(bump_version('2026.05.27.2', part=0), '2026.6.0.0')\n",
854+
"test_eq(bump_version('0.0.2026082005.post1'), '0.0.2026082005.post2')\n",
855+
"test_eq(bump_version('0.0.2026082005.post2', unbump=True), '0.0.2026082005.post1')\n",
856+
"test_eq(bump_version('0.0.2026082005.post1', part=2), '0.0.2026082006')"
848857
]
849858
},
850859
{

nbs/api/18_release.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,9 @@
10941094
"id": "9f1f82aa",
10951095
"metadata": {},
10961096
"source": [
1097-
"## Bump Version"
1097+
"## Bump Version\n",
1098+
"\n",
1099+
"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."
10981100
]
10991101
},
11001102
{
@@ -1107,7 +1109,7 @@
11071109
"#| export\n",
11081110
"@call_parse\n",
11091111
"def nbdev_bump_version(\n",
1110-
" part:int=2, # Part of version to bump\n",
1112+
" part:int=None, # Release part to bump; defaults to post when present, otherwise patch\n",
11111113
" unbump:bool=False): # Reduce version instead of increasing it\n",
11121114
" \"Increment version in __init__.py by one\"\n",
11131115
" cfg = get_config()\n",

0 commit comments

Comments
 (0)