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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ you may append a description between parens to the `file` keyword:
`$`).

Can be specified multiple times, bumpversion will try the serialization
formats beginning with the first and choose the last one where all values can
be represented like this:
formats beginning with the first (most complete) one and choose the last
one where all values can be represented like this:

```ini
serialize =
Expand Down
13 changes: 5 additions & 8 deletions bumpversion/version_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def value(self):
return self._value or self.config.optional_value

def copy(self):
return VersionPart(self._value)
return VersionPart(self._value, self.config)

def bump(self):
return VersionPart(self.config.bump(self.value), self.config)
Expand Down Expand Up @@ -148,14 +148,10 @@ def __init__(self, parse, serialize, search, replace, part_configs=None):

self.serialize_formats = serialize

if not part_configs:
part_configs = {}

self.part_configs = part_configs
self.part_configs = part_configs or {}
self.search = search
self.replace = replace


def order(self):
# currently, order depends on the first given serialization format
# this seems like a good idea because this should be the most complete format
Expand All @@ -177,7 +173,6 @@ def parse(self, version_string):

match = self.parse_regex.search(version_string)

_parsed = {}
if not match:
logger.warning(
"Evaluating 'parse' option: '%s' does not parse current version '%s'",
Expand All @@ -186,6 +181,7 @@ def parse(self, version_string):
)
return None

_parsed = {}
for key, value in match.groupdict().items():
_parsed[key] = VersionPart(value, self.part_configs.get(key))

Expand Down Expand Up @@ -277,7 +273,8 @@ def _choose_serialize_format(self, version, context):

return chosen

def serialize(self, version, context):
def serialize(self, version, context=None):
context = context or {}
serialized = self._serialize(
version, self._choose_serialize_format(version, context), context
)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_version_part.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ConfiguredVersionPartConfiguration,
NumericVersionPartConfiguration,
VersionPart,
VersionConfig,
)


Expand Down Expand Up @@ -36,6 +37,29 @@ def test_version_part_bump(confvpc):
assert vc.value == confvpc.bump(confvpc.first_value)


def test_bump_resets_lower_parts_to_default_value():
# See bug 134.
release_part_config = ConfiguredVersionPartConfiguration(
first_value="dev",
optional_value="prod",
values=["dev", "prod"],
)
version_config = VersionConfig(
parse=r"(?P<major>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?",
serialize=["{major}-{release}{build}", "{major}"],
part_configs={"release": release_part_config},
search=None,
replace=None,
)

# Start with version "0", mapping to "0-prod0".
# Bump `build` from 0 to 1.
# Part `release` should remain `prod` and be serialized as such.
version = version_config.parse("0")
new_version = version.bump("build", version_config.order())
assert version_config.serialize(new_version) == "0-prod1"


def test_version_part_check_optional_false(confvpc):
assert not VersionPart(confvpc.first_value, confvpc).bump().is_optional()

Expand Down