Add temporary pinning of increments (#197)

Fixes #196 - Add temporary pinning of increments

Co-authored-by: Manuel Barkhau <mbarkhau@gmail.com>
This commit is contained in:
Markus Holtermann 2022-12-02 00:43:25 +00:00 committed by GitHub
parent 5edb0ee3f4
commit 72227d3e75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 37 deletions

View file

@ -1,5 +1,15 @@
# Changelog for https://github.com/mbarkhau/bumpver
## BumpVer 2022.1120
- Fix [#196][gh_i196]: Add `--pin-increments`.
[gh_i196]: https://github.com/mbarkhau/bumpver/issues/196
Thank you [Markus Holtermann](https://github.com/MarkusH) for
this contribution.
## BumpVer 2022.1119
- Fix [#190][gh_i190]: Allow multiple patterns on the same line

View file

@ -605,6 +605,7 @@ Options:
--date <ISODATE> Set explicit date in format YYYY-0M-0D (e.g.
2021-05-13).
--pin-date Leave date components unchanged.
--pin-increments Leave the auto-increments INC0 and INC1
--tag-num Increment release tag number (rc1, rc2,
rc3..).
-t, --tag <NAME> Override release tag of current_version. Valid

View file

@ -37,6 +37,7 @@ pytest-cov
# https://github.com/pytest-dev/pytest-html/blob/master/CHANGES.rst
# pytest-html 2.0+ doesn't support python2.7
pytest-html<2.0
py
readme_renderer[md]
twine

View file

@ -131,10 +131,10 @@ jobs = 4
output-format = colorized
# Maximum number of locals for function / method body
max-locals = 16
max-locals = 17
# Maximum number of arguments for function / method
max-args = 8
max-args = 9
# Maximum number of branch for function / method body
max-branches = 14

View file

@ -224,6 +224,12 @@ def version_options(function: typ.Callable) -> typ.Callable:
default=False,
help="Increment release tag number (rc1, rc2, rc3..).",
),
click.option(
"--pin-increments",
is_flag=True,
default=False,
help="Leave the auto-increments INC0 and INC1 unchanged.",
),
click.option(
"--pin-date", is_flag=True, default=False, help="Leave date components unchanged."
),
@ -269,6 +275,7 @@ def test(
patch : bool = False,
tag : str = None,
tag_num : bool = False,
pin_increments: bool = False,
pin_date : bool = False,
date : typ.Optional[str] = None,
set_version : typ.Optional[str] = None,
@ -291,6 +298,7 @@ def test(
patch=patch,
tag=tag,
tag_num=tag_num,
pin_increments=pin_increments,
pin_date=pin_date,
maybe_date=maybe_date,
)
@ -526,6 +534,7 @@ def incr_dispatch(
patch : bool = False,
tag : str = None,
tag_num : bool = False,
pin_increments: bool = False,
pin_date : bool = False,
maybe_date : typ.Optional[dt.date] = None,
) -> typ.Optional[str]:
@ -562,6 +571,7 @@ def incr_dispatch(
patch=patch,
tag=tag,
tag_num=tag_num,
pin_increments=pin_increments,
pin_date=pin_date,
maybe_date=maybe_date,
)
@ -749,6 +759,7 @@ def update(
patch : bool = False,
tag : typ.Optional[str] = None,
tag_num : bool = False,
pin_increments: bool = False,
pin_date : bool = False,
date : typ.Optional[str] = None,
set_version : typ.Optional[str] = None,
@ -787,6 +798,7 @@ def update(
patch=patch,
tag=tag,
tag_num=tag_num,
pin_increments=pin_increments,
pin_date=pin_date,
maybe_date=maybe_date,
)

View file

@ -669,6 +669,7 @@ def _incr_numeric(
patch : bool,
tag : typ.Optional[str],
tag_num : bool,
pin_increments: bool,
) -> version.V2VersionInfo:
"""Increment (and reset to zero) non CalVer parts.
@ -685,6 +686,7 @@ def _incr_numeric(
... patch=True,
... tag='beta',
... tag_num=False,
... pin_increments=False,
... )
>>> (new_vinfo.major, new_vinfo.minor, new_vinfo.patch, new_vinfo.tag, new_vinfo.pytag, new_vinfo.num)
(1, 2, 4, 'beta', 'b', 0)
@ -704,6 +706,7 @@ def _incr_numeric(
pytag = version.PEP440_TAG_BY_TAG[tag]
cur_vinfo = cur_vinfo._replace(pytag=pytag)
if not pin_increments:
cur_vinfo = cur_vinfo._replace(inc0=cur_vinfo.inc0 + 1)
cur_vinfo = cur_vinfo._replace(inc1=cur_vinfo.inc1 + 1)
@ -743,6 +746,7 @@ def incr(
patch : bool = False,
tag : typ.Optional[str] = None,
tag_num : bool = False,
pin_increments: bool = False,
pin_date : bool = False,
maybe_date : typ.Optional[dt.date] = None,
) -> typ.Optional[str]:
@ -784,6 +788,7 @@ def incr(
patch=patch,
tag=tag,
tag_num=tag_num,
pin_increments=pin_increments,
)
new_version = format_version(cur_vinfo, raw_pattern)

View file

@ -156,6 +156,33 @@ def test_incr_pin_date(runner):
assert "Version: v2017.22000-alpha\n" in result.output
@pytest.mark.parametrize(
"version_pattern, old_version, new_version",
[
("vYYYY.INC0[-PATCH]", "v2017.0", "v2017.0-1"),
("vYYYY.INC0[-PATCH]", "v2017.0-1", "v2017.0-2"),
("vYYYY.INC1[-PATCH]", "v2017.1", "v2017.1-1"),
("vYYYY.INC1[-PATCH]", "v2017.1-1", "v2017.1-2"),
],
)
def test_incr_pin_increments(runner, version_pattern, old_version, new_version):
result = runner.invoke(
cli.cli,
[
'test',
"-vv",
"--pin-increments",
"--patch",
"--date",
"2017-12-01",
old_version,
version_pattern,
],
)
assert result.exit_code == 0
assert f"Version: {new_version}\n" in result.output
def test_incr_semver(runner):
semver_patterns = [
"{semver}",