add --pin-date flag

This commit is contained in:
Manuel Barkhau 2020-09-18 17:51:07 +00:00
parent 033a324488
commit f6f3a2fd00
4 changed files with 36 additions and 14 deletions

View file

@ -88,6 +88,9 @@ def cli(verbose: int = 0) -> None:
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
@click.option("--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option(
"-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged."
)
def test(
old_version: str,
pattern : str = "{pycalver}",
@ -96,6 +99,7 @@ def test(
major : bool = False,
minor : bool = False,
patch : bool = False,
pin_date : bool = False,
) -> None:
"""Increment a version number for demo purposes."""
_configure_logging(verbose=max(_VERBOSE, verbose))
@ -110,6 +114,7 @@ def test(
major=major,
minor=minor,
patch=patch,
pin_date=pin_date,
)
if new_version is None:
logger.error(f"Invalid version '{old_version}' and/or pattern '{pattern}'.")
@ -175,10 +180,11 @@ def _incr(
old_version: str,
pattern : str = "{pycalver}",
*,
release: str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
release : str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
is_v1_pattern = "{" in pattern
if is_v1_pattern:
@ -189,6 +195,7 @@ def _incr(
major=major,
minor=minor,
patch=patch,
pin_date=pin_date,
)
else:
return v2version.incr(
@ -198,6 +205,7 @@ def _incr(
major=major,
minor=minor,
patch=patch,
pin_date=pin_date,
)
@ -325,6 +333,9 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
@click.option("--minor", is_flag=True, default=False, help="Increment minor component.")
@click.option("--patch", is_flag=True, default=False, help="Increment patch component.")
@click.option(
"-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged."
)
def bump(
release : typ.Optional[str] = None,
verbose : int = 0,
@ -334,6 +345,7 @@ def bump(
major : bool = False,
minor : bool = False,
patch : bool = False,
pin_date : bool = False,
) -> None:
"""Increment the current version string and update project files."""
verbose = max(_VERBOSE, verbose)
@ -359,6 +371,7 @@ def bump(
major=major,
minor=minor,
patch=patch,
pin_date=pin_date,
)
if new_version is None:

View file

@ -434,10 +434,11 @@ def incr(
old_version: str,
pattern : str = "{pycalver}",
*,
release: str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
release : str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
"""Increment version string.
@ -451,7 +452,7 @@ def incr(
cur_vinfo = old_vinfo
cur_cal_nfo = cal_info()
cur_cal_nfo = _ver_to_cal_info(old_vinfo) if pin_date else cal_info()
old_date = (old_vinfo.year or 0 , old_vinfo.month or 0 , old_vinfo.dom or 0)
cur_date = (cur_cal_nfo.year or 0, cur_cal_nfo.month or 0, cur_cal_nfo.dom or 0)

View file

@ -586,10 +586,11 @@ def incr(
old_version: str,
pattern : str = "vYYYY0M.BUILD[-TAG]",
*,
release: str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
release : str = None,
major : bool = False,
minor : bool = False,
patch : bool = False,
pin_date: bool = False,
) -> typ.Optional[str]:
"""Increment version string.
@ -603,7 +604,7 @@ def incr(
cur_vinfo = old_vinfo
cur_cal_nfo = cal_info()
cur_cal_nfo = _ver_to_cal_info(old_vinfo) if pin_date else cal_info()
old_date = (old_vinfo.year_y or 0 , old_vinfo.month or 0 , old_vinfo.dom or 0)
cur_date = (cur_cal_nfo.year_y or 0, cur_cal_nfo.month or 0, cur_cal_nfo.dom or 0)

View file

@ -102,6 +102,13 @@ def test_incr_default(runner):
assert f"Version: {new_version}\n" in result.output
def test_incr_pin_date(runner):
old_version = "v201701.0999-alpha"
result = runner.invoke(cli, ['test', "-vv", "--pin-date", old_version])
assert result.exit_code == 0
assert "Version: v201701.11000-alpha\n" in result.output
def test_incr_semver(runner):
semver_pattern = "{MAJOR}.{MINOR}.{PATCH}"
old_version = "0.1.0"