c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 134 forks source link

[usage question] Bumping patch while removing post? #174

Closed bsolomon1124 closed 3 years ago

bsolomon1124 commented 3 years ago

We follow a versioning scheme that is mostly PEP 440 with some tweaks:

It comes down to 4 'groups' of versions as shown below:

1.2.3             # (1) final

1.2.3.dev0        # (2) prerelease
1.2.3.a0
1.2.3.alpha0
1.2.3.b0
1.2.3.beta0
1.2.3.rc0

1.2.3.rc3.post0   # (3) postrelease (of a pre-release version)

1.2.3.post0       # (4) postrelease (of a final version)

Regex example: https://regex101.com/r/wupvcm/1

Reproducible single-file project:

cat << EOF > __init__.py
__version__ = "1.0.0.a2.post0"
EOF

cat << EOF > setup.cfg
[bumpversion]
current_version = 1.0.0.a2.post0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<pre>(?:a|alpha|b|beta|d|dev|rc)\d+))?(\.(?P<post>post\d+))?
tag = True
commit = True
serialize =
  {major}.{minor}.{patch}
  {major}.{minor}.{patch}.{post}
  {major}.{minor}.{patch}.{pre}
  {major}.{minor}.{patch}.{pre}.{post}

[bumpversion:file:__init__.py]
EOF

Now we run:

$ bump2version --new-version 1.0.0.a3 pre

Actual result:

$ cat __init__.py 
__version__ = "1.0.0.a3.0"

Expected result:

$ cat __init__.py 
__version__ = "1.0.0.a3"

What would be the proper invocation or configuration to (1) remove the .postX while (2) bumping the pre segment from a2 to a3?

bsolomon1124 commented 3 years ago

Left a similar question with some scheme modifications on Stack Overflow: https://stackoverflow.com/q/65083808/7954504.

pdemarti commented 3 years ago

Please see my answer on StackOverflow.

Since pre and post each have both a string prefix and a number, I believe it is necessary to split them accordingly. For example, the pre part could be split into a prekind (the string) and a pre (the number). Then, the nice thing is that you can increment prekind ('dev' to 'alpha' to 'beta' etc.) independently of the issue number (a sequence, as usual).

On the answer linked above, I've put both a complete configuration and an example with a number of invocations in sequence to show the various mutations that are possible.

bsolomon1124 commented 3 years ago

Closing as the linked answer seems to be a full-fledged working solution.