callowayproject / bump-my-version

A small command line tool to simplify releasing software by updating all version strings in your source code by the correct increment and optionally commit and tag the changes.
https://callowayproject.github.io/bump-my-version/
MIT License
305 stars 19 forks source link

Provided semantic versioning pre-release example results in PEP440 incompatibility ? #205

Closed ddewaele closed 2 months ago

ddewaele commented 2 months ago

Description

According to the README.md, with the following pyproject.toml (inspired by the README.md for semantic versioning in the pre-release versions section)

[tool.bumpversion]
current_version = "0.0.22"
parse = """(?x)
    (?P<major>0|[1-9]\\d*)\\.
    (?P<minor>0|[1-9]\\d*)\\.
    (?P<patch>0|[1-9]\\d*)
    (?:
        -                             # dash separator for pre-release section
        (?P<pre_l>[a-zA-Z-]+)         # pre-release label
        (?P<pre_n>0|[1-9]\\d*)        # pre-release version number
    )?                                # pre-release section is optional
"""
serialize = [
    "{major}.{minor}.{patch}-{pre_l}{pre_n}",
    "{major}.{minor}.{patch}",
]
search = "{current_version}"
replace = "{new_version}"
regex = true
ignore_missing_version = false
ignore_missing_files = false
tag = true
sign_tags = false
tag_name = "v{new_version}"
tag_message = "[skip ci] Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = true
message = "[skip ci] Bump version: {current_version} → {new_version}"
commit_args = ""

[tool.bumpversion.parts.pre_l]
values = ["dev", "rc", "final"]
optional_value = "final"

The following bump versions are possible, including 0.0.22-final1

bump-my-version show-bump
0.0.22 ── bump ─┬─ major ─ 1.0.0-dev0
                ├─ minor ─ 0.1.0-dev0
                ├─ patch ─ 0.0.23-dev0
                ├─ pre_l ─ invalid: The part has already the maximum value among ['dev', 'rc', 'final'] and cannot be bumped.
                ╰─ pre_n ─ 0.0.22-final1

However, generating a 0.0.22-final1 version will lead to pep440 compatibility issues :

+ python -m build
* Creating isolated environment: venv+pip...
* Installing packages in isolated environment:
  - build
  - setuptools>=69
  - wheel
* Getting build dependencies for sdist...
configuration error: `project.version` must be pep440
DESCRIPTION:
    The version of the project as supported by :pep:`440`.
GIVEN VALUE:
    "0.0.22-final1"
OFFENDING RULE: 'format'
DEFINITION:
    {
        "type": "string",
        "format": "pep440"
    }

Would it be interesting to provide more clarification on this in the README ? Or was the example provided intentional ?

coordt commented 2 months ago

The instructions later on in the readme remove that issue.

In bump-my-version's case, 0.0.22 is the same as 0.0.22-final0, but serializing the version number to a string sees that final is optional when linked to a 0, so it removes it.

The pre-n number is problematic, so that is why the referenced section removes and automates its value.