From 98647519c20cb59c923f5717eefdf8bf7f381004 Mon Sep 17 00:00:00 2001 From: Manuel Barkhau Date: Sat, 3 Oct 2020 23:44:09 +0000 Subject: [PATCH] more consistent internal naming (release -> tag) --- src/pycalver/__main__.py | 39 +++++++++++++++++++++------------------ src/pycalver/v1version.py | 6 +++--- src/pycalver/v2version.py | 2 +- test/test_version.py | 12 ++++++------ 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/pycalver/__main__.py b/src/pycalver/__main__.py index 3ac32db..1c45e6b 100755 --- a/src/pycalver/__main__.py +++ b/src/pycalver/__main__.py @@ -69,7 +69,7 @@ def _configure_logging(verbose: int = 0) -> None: logger.debug("Logging configured.") -VALID_RELEASE_VALUES = ("alpha", "beta", "rc", "post", "final") +VALID_RELEASE_TAG_VALUES = ("alpha", "beta", "rc", "post", "final") _current_date = dt.date.today().isoformat() @@ -93,15 +93,15 @@ def _validate_date(date: typ.Optional[str], pin_date: bool) -> typ.Optional[dt.d sys.exit(1) -def _validate_release_tag(release: typ.Optional[str]) -> None: - if release is None: +def _validate_release_tag(tag: typ.Optional[str]) -> None: + if tag is None: return - if release in VALID_RELEASE_VALUES: + if tag in VALID_RELEASE_TAG_VALUES: return - logger.error(f"Invalid argument --release={release}") - logger.error(f"Valid arguments are: {', '.join(VALID_RELEASE_VALUES)}") + logger.error(f"Invalid argument --release={tag}") + logger.error(f"Valid arguments are: {', '.join(VALID_RELEASE_TAG_VALUES)}") sys.exit(1) @@ -124,7 +124,7 @@ def cli(verbose: int = 0) -> None: metavar="", help=( f"Override release name of current_version. Valid options are: " - f"{', '.join(VALID_RELEASE_VALUES)}." + f"{', '.join(VALID_RELEASE_TAG_VALUES)}." ), ) @click.option("--major" , is_flag=True, default=False, help="Increment major component.") @@ -154,13 +154,14 @@ def test( _configure_logging(verbose=max(_VERBOSE, verbose)) raw_pattern = pattern # use internal naming convention - _validate_release_tag(release) + tag = release # use internal naming convention + _validate_release_tag(tag) _date = _validate_date(date, pin_date) - new_version = _incr( + new_version = incr_dispatch( old_version, raw_pattern=raw_pattern, - release=release, + tag=tag, major=major, minor=minor, patch=patch, @@ -337,11 +338,11 @@ def _print_diff(cfg: config.Config, new_version: str) -> None: sys.exit(1) -def _incr( +def incr_dispatch( old_version: str, raw_pattern: str, *, - release : str = None, + tag : str = None, major : bool = False, minor : bool = False, patch : bool = False, @@ -351,6 +352,7 @@ def _incr( ) -> 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) + if _VERBOSE: if has_v1_part: pattern = v1patterns.compile_pattern(raw_pattern) @@ -364,7 +366,7 @@ def _incr( return v1version.incr( old_version, raw_pattern=raw_pattern, - release=release, + tag=tag, major=major, minor=minor, patch=patch, @@ -376,7 +378,7 @@ def _incr( return v2version.incr( old_version, raw_pattern=raw_pattern, - release=release, + tag=tag, major=major, minor=minor, patch=patch, @@ -501,7 +503,7 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config: metavar="", help=( f"Override release name of current_version. Valid options are: " - f"{', '.join(VALID_RELEASE_VALUES)}." + f"{', '.join(VALID_RELEASE_TAG_VALUES)}." ), ) @click.option( @@ -542,7 +544,8 @@ def bump( verbose = max(_VERBOSE, verbose) _configure_logging(verbose) - _validate_release_tag(release) + tag = release # use internal naming convention + _validate_release_tag(tag) _date = _validate_date(date, pin_date) _, cfg = config.init(project_path=".") @@ -554,10 +557,10 @@ def bump( cfg = _update_cfg_from_vcs(cfg, fetch) old_version = cfg.current_version - new_version = _incr( + new_version = incr_dispatch( old_version, raw_pattern=cfg.version_pattern, - release=release, + tag=tag, major=major, minor=minor, patch=patch, diff --git a/src/pycalver/v1version.py b/src/pycalver/v1version.py index 1cecbd2..dac43a0 100644 --- a/src/pycalver/v1version.py +++ b/src/pycalver/v1version.py @@ -374,7 +374,7 @@ def incr( old_version: str, raw_pattern: str = "{pycalver}", *, - release : typ.Optional[str] = None, + tag : typ.Optional[str] = None, major : bool = False, minor : bool = False, patch : bool = False, @@ -410,8 +410,8 @@ def incr( cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1) if release_num: raise NotImplementedError("--release-num not supported for old style patterns") - if release: - cur_vinfo = cur_vinfo._replace(tag=release) + if tag: + cur_vinfo = cur_vinfo._replace(tag=tag) new_version = format_version(cur_vinfo, raw_pattern) if new_version == old_version: diff --git a/src/pycalver/v2version.py b/src/pycalver/v2version.py index 3af15e1..fc7e88e 100644 --- a/src/pycalver/v2version.py +++ b/src/pycalver/v2version.py @@ -638,7 +638,7 @@ def incr( old_version: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]", *, - release : typ.Optional[str] = None, + tag : typ.Optional[str] = None, major : bool = False, minor : bool = False, patch : bool = False, diff --git a/test/test_version.py b/test/test_version.py index 4025ec4..7dadb50 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -22,20 +22,20 @@ def test_bump_beta(): cur_version = "v201712.0001-beta" assert cur_version < v1version.incr(cur_version) assert v1version.incr(cur_version).endswith("-beta") - assert v1version.incr(cur_version, release="alpha").endswith("-alpha") - assert v1version.incr(cur_version, release="final").endswith("0002") + assert v1version.incr(cur_version, tag="alpha").endswith("-alpha") + assert v1version.incr(cur_version, tag="final").endswith("0002") def test_bump_final(): cur_version = "v201712.0001" assert cur_version < v1version.incr(cur_version) assert v1version.incr(cur_version).endswith(".0002") - assert v1version.incr(cur_version, release="alpha").endswith("-alpha") + assert v1version.incr(cur_version, tag="alpha").endswith("-alpha") - assert v1version.incr(cur_version, release="final").endswith(".0002") + assert v1version.incr(cur_version, tag="final").endswith(".0002") pre_version = cur_version + "-beta" - assert v1version.incr(pre_version, release="final").endswith(".0002") + assert v1version.incr(pre_version, tag="final").endswith(".0002") def test_bump_future(): @@ -56,7 +56,7 @@ def test_bump_random(monkeypatch): for _ in range(1000): cur_date += dt.timedelta(days=int((1 + random.random()) ** 10)) new_version = v1version.incr( - cur_version, release=random.choice([None, "alpha", "beta", "rc", "final", "post"]) + cur_version, tag=random.choice([None, "alpha", "beta", "rc", "final", "post"]) ) assert cur_version < new_version cur_version = new_version