Repository: callowayproject/bump-my-version (python)

Issue:
Zero-padded version parts are not working
              It seems that this fix was removed with some refactoring happened in #112. Tried with version 0.20.1 and the following config parameters:
```
current_version = "5.06.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor:02}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
```
Increasing minor would result in version 5.70.0 which is obviously wrong. Any chances we get this functionality back? Or is there any other possibility to have fixed length version numbers?

_Originally posted by @reindlt in https://github.com/callowayproject/bump-my-version/issues/26#issuecomment-2071756686_
            

Pull request description:
Fixed the rendering of numeric version components.
- Numeric version components now will attempt to render its value as an integer and fall back to the parsed value.
- Fixes #179 

Patch:
diff --git a/bumpversion/versioning/models.py b/bumpversion/versioning/models.py
index ac0069ee..9c7d9cb7 100644
--- a/bumpversion/versioning/models.py
+++ b/bumpversion/versioning/models.py
@@ -216,9 +216,9 @@ class Version:
         self.components = components
         self.original = original
 
-    def values(self) -> Dict[str, str]:
+    def values(self) -> Dict[str, VersionComponent]:
         """Return the values of the parts."""
-        return {key: value.value for key, value in self.components.items()}
+        return dict(self.components.items())
 
     def __getitem__(self, key: str) -> VersionComponent:
         return self.components[key]


Test patch:
diff --git a/tests/test_versioning/test_serialization.py b/tests/test_versioning/test_serialization.py
index 3cb9e56c..0bf99315 100644
--- a/tests/test_versioning/test_serialization.py
+++ b/tests/test_versioning/test_serialization.py
@@ -68,6 +68,11 @@ class TestParseVersion:
         pattern = r"MAJOR=(?P<major>\d+)\nMINOR=(?P<minor>\d+)\nPATCH=(?P<patch>\d+)\n"
         assert parse_version("MAJOR=31\nMINOR=0\nPATCH=3\n", pattern) == {"major": "31", "minor": "0", "patch": "3"}
 
+    def test_parse_pattern_with_zero_padding(self):
+        """A parse pattern with zero padding should be parsed correctly."""
+        pattern = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
+        assert parse_version("5.06.0", pattern) == {"major": "5", "minor": "06", "patch": "0"}
+
 
 class TestSerialize:
     """Test the serialize function."""
@@ -196,6 +201,11 @@ class TestSerialize:
                 == "1.2.3+build.1"
             )
 
+        def test_zero_padding(self):
+            """A numeric component with zero-padding notation should be rendered correctly."""
+            version = semver_spec().create_version({"major": "1", "minor": "2", "patch": "3"})
+            assert serialize(version, serialize_patterns=["{major}.{minor:02}.{patch}"], context={}) == "1.02.3"
+
     class TestRaisesError:
         def test_if_context_is_missing_values(self):
             """An error is raised if not all parts required in the format have values."""