Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions nbdev/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion nbdev/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 11 additions & 9 deletions nbs/api/01_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions nbs/api/18_release.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions nbs/api/19_diff.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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'))"
]
},
{
Expand Down