Skip to content

Commit

Permalink
Integrate independent feature from ADVbumpversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrivet committed Sep 16, 2021
1 parent a58e20d commit b581373
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ def _load_configuration(config_file, explicit_config, defaults):
)
ThisVersionPartConfiguration = ConfiguredVersionPartConfiguration

if config.has_option(section_name, 'independent'):
section_config['independent'] = config.getboolean(section_name, 'independent')

part_configs[section_value] = ThisVersionPartConfiguration(
**section_config
)
Expand Down
6 changes: 4 additions & 2 deletions bumpversion/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NumericFunction:

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

def __init__(self, first_value=None):
def __init__(self, first_value=None, independent=False):

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

self.first_value = str(first_value)
self.optional_value = self.first_value
self.independent = independent

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

def __init__(self, values, optional_value=None, first_value=None):
def __init__(self, values, optional_value=None, first_value=None, independent=False):

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

self.first_value = first_value
self.independent = independent

def bump(self, value):
try:
Expand Down
9 changes: 8 additions & 1 deletion bumpversion/version_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def first_value(self):
def optional_value(self):
return str(self.function.optional_value)

@property
def independent(self):
return self.function.independent

def bump(self, value=None):
return self.function.bump(value)

Expand Down Expand Up @@ -73,6 +77,9 @@ def bump(self):
def is_optional(self):
return self.value == self.config.optional_value

def is_independent(self):
return self.config.independent

def __format__(self, format_spec):
return self.value

Expand Down Expand Up @@ -117,7 +124,7 @@ def bump(self, part_name, order):
if label == part_name:
new_values[label] = self._values[label].bump()
bumped = True
elif bumped:
elif bumped and not self._values[label].is_independent():
new_values[label] = self._values[label].null()
else:
new_values[label] = self._values[label].copy()
Expand Down

0 comments on commit b581373

Please sign in to comment.