From 72227d3e75ddbd84ea032fdc04828d509871d828 Mon Sep 17 00:00:00 2001 From: Markus Holtermann Date: Fri, 2 Dec 2022 00:43:25 +0000 Subject: [PATCH] Add temporary pinning of increments (#197) Fixes #196 - Add temporary pinning of increments Co-authored-by: Manuel Barkhau --- CHANGELOG.md | 10 ++++++++ README.md | 1 + requirements/integration.txt | 1 + setup.cfg | 4 +-- src/bumpver/cli.py | 48 ++++++++++++++++++++++-------------- src/bumpver/v2version.py | 39 ++++++++++++++++------------- test/test_cli.py | 27 ++++++++++++++++++++ 7 files changed, 93 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ae0a9..b712217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 2553a16..b8ed1ad 100644 --- a/README.md +++ b/README.md @@ -605,6 +605,7 @@ Options: --date 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 Override release tag of current_version. Valid diff --git a/requirements/integration.txt b/requirements/integration.txt index ef13b3f..1cbe1ab 100644 --- a/requirements/integration.txt +++ b/requirements/integration.txt @@ -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 diff --git a/setup.cfg b/setup.cfg index 7eb8350..43a0731 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/bumpver/cli.py b/src/bumpver/cli.py index 92a6deb..1e758f6 100755 --- a/src/bumpver/cli.py +++ b/src/bumpver/cli.py @@ -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." ), @@ -261,17 +267,18 @@ def cli(verbose: int = 0) -> None: @verbose_option @version_options def test( - old_version: str, - pattern : str, - verbose : int = 0, - major : bool = False, - minor : bool = False, - patch : bool = False, - tag : str = None, - tag_num : bool = False, - pin_date : bool = False, - date : typ.Optional[str] = None, - set_version: typ.Optional[str] = None, + old_version : str, + pattern : str, + verbose : int = 0, + major : bool = False, + minor : bool = False, + 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, ) -> None: """Increment a version number for demo purposes.""" _configure_logging(verbose=max(_VERBOSE, verbose)) @@ -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, ) @@ -521,13 +529,14 @@ def incr_dispatch( old_version: str, raw_pattern: str, *, - major : bool = False, - minor : bool = False, - patch : bool = False, - tag : str = None, - tag_num : bool = False, - pin_date : bool = False, - maybe_date: typ.Optional[dt.date] = None, + major : bool = False, + minor : bool = False, + 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]: v1_parts = list(v1patterns.PART_PATTERNS) + list(v1patterns.FULL_PART_FORMATS) has_v1_part = any("{" + part + "}" in raw_pattern for part in v1_parts) @@ -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, ) diff --git a/src/bumpver/v2version.py b/src/bumpver/v2version.py index a5c8480..9438334 100644 --- a/src/bumpver/v2version.py +++ b/src/bumpver/v2version.py @@ -661,14 +661,15 @@ def _reset_rollover_fields( def _incr_numeric( - raw_pattern: str, - old_vinfo : version.V2VersionInfo, - cur_vinfo : version.V2VersionInfo, - major : bool, - minor : bool, - patch : bool, - tag : typ.Optional[str], - tag_num : bool, + raw_pattern : str, + old_vinfo : version.V2VersionInfo, + cur_vinfo : version.V2VersionInfo, + major : bool, + minor : bool, + 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,8 +706,9 @@ def _incr_numeric( pytag = version.PEP440_TAG_BY_TAG[tag] cur_vinfo = cur_vinfo._replace(pytag=pytag) - cur_vinfo = cur_vinfo._replace(inc0=cur_vinfo.inc0 + 1) - cur_vinfo = cur_vinfo._replace(inc1=cur_vinfo.inc1 + 1) + if not pin_increments: + cur_vinfo = cur_vinfo._replace(inc0=cur_vinfo.inc0 + 1) + cur_vinfo = cur_vinfo._replace(inc1=cur_vinfo.inc1 + 1) # prevent truncation of leading zeros if int(cur_vinfo.bid) < 1000: @@ -738,13 +741,14 @@ def incr( old_version: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG]", *, - major : bool = False, - minor : bool = False, - patch : bool = False, - tag : typ.Optional[str] = None, - tag_num : bool = False, - pin_date : bool = False, - maybe_date: typ.Optional[dt.date] = None, + major : bool = False, + minor : bool = False, + 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]: """Increment version string. @@ -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) diff --git a/test/test_cli.py b/test/test_cli.py index a177d06..5f96a59 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -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}",