Skip to content

Commit bc95374

Browse files
authored
Merge pull request #234 from andrivet/feature-independent
Implementation of the independent feature from ADVbumpversion
2 parents f8e6d14 + 4adeeef commit bc95374

File tree

6 files changed

+91
-5
lines changed

6 files changed

+91
-5
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,32 @@ first_value = 1
341341
`bump2version release` would bump `1.alpha1` to `1.beta0`, starting
342342
the build at `0`.
343343

344+
345+
#### `independent =`
346+
**default**: `False`
347+
348+
When this value is set to `True`, the part is not reset when other parts are incremented. Its incrementation is
349+
independent of the other parts. It is in particular useful when you have a build number in your version that is
350+
incremented independently of the actual version.
351+
352+
Example:
353+
354+
```ini
355+
[bumpversion]
356+
current_version: 2.1.6-5123
357+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-(?P<build>\d+)
358+
serialize = {major}.{minor}.{patch}-{build}
359+
360+
[bumpversion:file:VERSION.txt]
361+
362+
[bumpversion:part:build]
363+
independent = True
364+
```
365+
366+
Here, `bump2version build` would bump `2.1.6-5123` to `2.1.6-5124`. Executing`bump2version major`
367+
would bump `2.1.6-5124` to `3.0.0-5124` without resetting the build number.
368+
369+
344370
### Configuration file -- File specific configuration
345371

346372
This configuration is in the section: `[bumpversion:file:…]` or `[bumpversion:glob:…]`

RELATED.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* [tbump](https://github.com/tankerhq/tbump) is a complete rewrite, with a nicer UX and additional features, like running commands (aka hooks) before or after the bump. It only works for Git repos right now.
88

99
* [ADVbumpversion](https://github.com/andrivet/advbumpversion) is another fork.
10-
It offers some features which are still work in progress here; it's
11-
definitely our desire to merge back (issue [#121](https://github.com/c4urself/bump2version/issues/121)).
10+
It offered some features that are now incorporated by its author into `bump2version`.
11+
This fork is thus now deprecated, and it recommends to use `bump2version`
12+
(issue [#121](https://github.com/c4urself/bump2version/issues/121)).
1213

1314
* [zest.releaser](https://pypi.org/project/zest.releaser/) manages
1415
your Python package releases and keeps the version number in one location.

bumpversion/cli.py

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ def _load_configuration(config_file, explicit_config, defaults):
327327
)
328328
ThisVersionPartConfiguration = ConfiguredVersionPartConfiguration
329329

330+
if config.has_option(section_name, 'independent'):
331+
section_config['independent'] = config.getboolean(section_name, 'independent')
332+
330333
part_configs[section_value] = ThisVersionPartConfiguration(
331334
**section_config
332335
)

bumpversion/functions.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NumericFunction:
1717

1818
FIRST_NUMERIC = re.compile(r"([^\d]*)(\d+)(.*)")
1919

20-
def __init__(self, first_value=None):
20+
def __init__(self, first_value=None, independent=False):
2121

2222
if first_value is not None:
2323
try:
@@ -33,6 +33,7 @@ def __init__(self, first_value=None):
3333

3434
self.first_value = str(first_value)
3535
self.optional_value = self.first_value
36+
self.independent = independent
3637

3738
def bump(self, value):
3839
part_prefix, part_numeric, part_suffix = self.FIRST_NUMERIC.search(
@@ -57,7 +58,7 @@ class ValuesFunction:
5758
you get a ValueError exception.
5859
"""
5960

60-
def __init__(self, values, optional_value=None, first_value=None):
61+
def __init__(self, values, optional_value=None, first_value=None, independent=False):
6162

6263
if not values:
6364
raise ValueError("Version part values cannot be empty")
@@ -87,6 +88,7 @@ def __init__(self, values, optional_value=None, first_value=None):
8788
)
8889

8990
self.first_value = first_value
91+
self.independent = independent
9092

9193
def bump(self, value):
9294
try:

bumpversion/version_part.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def first_value(self):
3030
def optional_value(self):
3131
return str(self.function.optional_value)
3232

33+
@property
34+
def independent(self):
35+
return self.function.independent
36+
3337
def bump(self, value=None):
3438
return self.function.bump(value)
3539

@@ -73,6 +77,9 @@ def bump(self):
7377
def is_optional(self):
7478
return self.value == self.config.optional_value
7579

80+
def is_independent(self):
81+
return self.config.independent
82+
7683
def __format__(self, format_spec):
7784
return self.value
7885

@@ -117,7 +124,7 @@ def bump(self, part_name, order):
117124
if label == part_name:
118125
new_values[label] = self._values[label].bump()
119126
bumped = True
120-
elif bumped:
127+
elif bumped and not self._values[label].is_independent():
121128
new_values[label] = self._values[label].null()
122129
else:
123130
new_values[label] = self._values[label].copy()

tests/test_cli.py

+47
Original file line numberDiff line numberDiff line change
@@ -2345,3 +2345,50 @@ def test_2optional_mixed_2positional(self):
23452345

23462346
assert positional == ['minor', 'setup.py']
23472347
assert optional == ['--allow-dirty', '-m', '"Commit"']
2348+
2349+
2350+
def test_build_number_configuration(tmpdir):
2351+
tmpdir.join("VERSION.txt").write("2.1.6-5123")
2352+
tmpdir.chdir()
2353+
tmpdir.join(".bumpversion.cfg").write(dedent(r"""
2354+
[bumpversion]
2355+
current_version: 2.1.6-5123
2356+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-(?P<build>\d+)
2357+
serialize = {major}.{minor}.{patch}-{build}
2358+
2359+
[bumpversion:file:VERSION.txt]
2360+
2361+
[bumpversion:part:build]
2362+
independent = True
2363+
"""))
2364+
2365+
main(['build'])
2366+
assert '2.1.6-5124' == tmpdir.join("VERSION.txt").read()
2367+
2368+
main(['major'])
2369+
assert '3.0.0-5124' == tmpdir.join("VERSION.txt").read()
2370+
2371+
main(['build'])
2372+
assert '3.0.0-5125' == tmpdir.join("VERSION.txt").read()
2373+
2374+
2375+
def test_independent_falsy_value_in_config_does_not_bump_independently(tmpdir):
2376+
tmpdir.join("VERSION").write("2.1.0-5123")
2377+
tmpdir.chdir()
2378+
tmpdir.join(".bumpversion.cfg").write(dedent(r"""
2379+
[bumpversion]
2380+
current_version: 2.1.0-5123
2381+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-(?P<build>\d+)
2382+
serialize = {major}.{minor}.{patch}-{build}
2383+
2384+
[bumpversion:file:VERSION]
2385+
2386+
[bumpversion:part:build]
2387+
independent = 0
2388+
"""))
2389+
2390+
main(['build'])
2391+
assert '2.1.0-5124' == tmpdir.join("VERSION").read()
2392+
2393+
main(['major'])
2394+
assert '3.0.0-0' == tmpdir.join("VERSION").read()

0 commit comments

Comments
 (0)